source: SHVCSoftware/branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 447

Last change on this file since 447 was 445, checked in by seregin, 12 years ago

enable layer-specific CTB structure

  • Property svn:eol-style set to native
File size: 53.8 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#if FAST_BIT_EST
42#include "TLibCommon/ContextModel.h"
43#endif
44
45//! \ingroup TLibEncoder
46//! \{
47#if SVC_EXTENSION 
48Int TEncTop::m_iSPSIdCnt = 0;
49Int TEncTop::m_iPPSIdCnt = 0;
50TComVPS TEncCfg::m_cVPS;
51#endif
52
53// ====================================================================================================================
54// Constructor / destructor / create / destroy
55// ====================================================================================================================
56
57TEncTop::TEncTop()
58{
59  m_iPOCLast          = -1;
60  m_iNumPicRcvd       =  0;
61  m_uiNumAllPicCoded  =  0;
62  m_pppcRDSbacCoder   =  NULL;
63  m_pppcBinCoderCABAC =  NULL;
64  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
65#if ENC_DEC_TRACE
66  g_hTrace = fopen( "TraceEnc.txt", "wb" );
67  g_bJustDoIt = g_bEncDecTraceDisable;
68  g_nSymbolCounter = 0;
69#endif
70
71  m_iMaxRefPicNum     = 0;
72
73#if FAST_BIT_EST
74  ContextModel::buildNextStateTable();
75#endif
76
77  m_pcSbacCoders           = NULL;
78  m_pcBinCoderCABACs       = NULL;
79  m_ppppcRDSbacCoders      = NULL;
80  m_ppppcBinCodersCABAC    = NULL;
81  m_pcRDGoOnSbacCoders     = NULL;
82  m_pcRDGoOnBinCodersCABAC = NULL;
83  m_pcBitCounters          = NULL;
84  m_pcRdCosts              = NULL;
85#if SVC_EXTENSION
86  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
87#if REF_IDX_MFM
88  m_bMFMEnabledFlag = false;
89#endif
90#if SCALED_REF_LAYER_OFFSETS
91  m_numScaledRefLayerOffsets = 0;
92#endif
93#endif
94#if POC_RESET_FLAG
95  m_pocAdjustmentValue     = 0;
96#endif
97}
98
99TEncTop::~TEncTop()
100{
101#if ENC_DEC_TRACE
102  fclose( g_hTrace );
103#endif
104}
105
106Void TEncTop::create ()
107{
108#if !SVC_EXTENSION
109  // initialize global variables
110  initROM();
111#endif
112
113  // create processing unit classes
114#if SVC_EXTENSION
115  m_cGOPEncoder.        create( m_layerId );
116#else
117  m_cGOPEncoder.        create();
118#endif
119  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
120  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
121  if (m_bUseSAO)
122  {
123    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
124    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
125    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
126    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
127    m_cEncSAO.createEncBuffer();
128  }
129#if ADAPTIVE_QP_SELECTION
130  if (m_bUseAdaptQpSelect)
131  {
132    m_cTrQuant.initSliceQpDelta();
133  }
134#endif
135  m_cLoopFilter.        create( g_uiMaxCUDepth );
136 
137#if RATE_CONTROL_LAMBDA_DOMAIN
138  if ( m_RCEnableRateControl )
139  {
140    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
141                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
142  }
143#else
144  m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
145#endif
146  // if SBAC-based RD optimization is used
147  if( m_bUseSBACRD )
148  {
149    m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
150#if FAST_BIT_EST
151    m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
152#else
153    m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
154#endif
155   
156    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
157    {
158      m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
159#if FAST_BIT_EST
160      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
161#else
162      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
163#endif
164     
165      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
166      {
167        m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
168#if FAST_BIT_EST
169        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
170#else
171        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
172#endif
173        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
174      }
175    }
176  }
177
178#if LAYER_CTB
179  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
180  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
181  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
182  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
183#endif
184}
185
186/**
187 - Allocate coders required for wavefront for the nominated number of substreams.
188 .
189 \param iNumSubstreams Determines how much information to allocate.
190 */
191Void TEncTop::createWPPCoders(Int iNumSubstreams)
192{
193  if (m_pcSbacCoders != NULL)
194  {
195    return; // already generated.
196  }
197
198  m_iNumSubstreams         = iNumSubstreams;
199  m_pcSbacCoders           = new TEncSbac       [iNumSubstreams];
200  m_pcBinCoderCABACs       = new TEncBinCABAC   [iNumSubstreams];
201  m_pcRDGoOnSbacCoders     = new TEncSbac       [iNumSubstreams];
202  m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC   [iNumSubstreams];
203  m_pcBitCounters          = new TComBitCounter [iNumSubstreams];
204  m_pcRdCosts              = new TComRdCost     [iNumSubstreams];
205
206  for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ )
207  {
208    m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] );
209    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
210  }
211  if( m_bUseSBACRD )
212  {
213    m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
214    m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
215    for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
216    {
217      m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
218      m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
219     
220      for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
221      {
222        m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
223        m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
224
225        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
226        {
227          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
228          m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
229          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
230        }
231      }
232    }
233  }
234}
235
236Void TEncTop::destroy ()
237{
238  // destroy processing unit classes
239  m_cGOPEncoder.        destroy();
240  m_cSliceEncoder.      destroy();
241  m_cCuEncoder.         destroy();
242  if (m_cSPS.getUseSAO())
243  {
244    m_cEncSAO.destroy();
245    m_cEncSAO.destroyEncBuffer();
246  }
247  m_cLoopFilter.        destroy();
248  m_cRateCtrl.          destroy();
249  // SBAC RD
250  if( m_bUseSBACRD )
251  {
252    Int iDepth;
253    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
254    {
255      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
256      {
257        delete m_pppcRDSbacCoder[iDepth][iCIIdx];
258        delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
259      }
260    }
261   
262    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
263    {
264      delete [] m_pppcRDSbacCoder[iDepth];
265      delete [] m_pppcBinCoderCABAC[iDepth];
266    }
267   
268    delete [] m_pppcRDSbacCoder;
269    delete [] m_pppcBinCoderCABAC;
270
271    for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
272    {
273      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
274      {
275        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
276        {
277          delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
278          delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
279        }
280      }
281
282      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
283      {
284        delete [] m_ppppcRDSbacCoders  [ui][iDepth];
285        delete [] m_ppppcBinCodersCABAC[ui][iDepth];
286      }
287      delete[] m_ppppcRDSbacCoders  [ui];
288      delete[] m_ppppcBinCodersCABAC[ui];
289    }
290    delete[] m_ppppcRDSbacCoders;
291    delete[] m_ppppcBinCodersCABAC;
292  }
293  delete[] m_pcSbacCoders;
294  delete[] m_pcBinCoderCABACs;
295  delete[] m_pcRDGoOnSbacCoders; 
296  delete[] m_pcRDGoOnBinCodersCABAC;
297  delete[] m_pcBitCounters;
298  delete[] m_pcRdCosts;
299 
300#if SVC_EXTENSION
301  for(Int i=0; i<MAX_NUM_REF; i++)
302  {
303    if(m_cIlpPic[i])
304    {
305      m_cIlpPic[i]->destroy();
306      delete m_cIlpPic[i];
307      m_cIlpPic[i] = NULL;
308    }
309  }
310#else
311  // destroy ROM
312  destroyROM();
313#endif
314  return;
315}
316
317Void TEncTop::init(Bool isFieldCoding)
318{
319  // initialize SPS
320  xInitSPS();
321 
322  /* set the VPS profile information */
323  *m_cVPS.getPTL() = *m_cSPS.getPTL();
324  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
325  // initialize PPS
326  m_cPPS.setSPS(&m_cSPS);
327  xInitPPS();
328  xInitRPS(isFieldCoding);
329
330  xInitPPSforTiles();
331
332  // initialize processing unit classes
333  m_cGOPEncoder.  init( this );
334  m_cSliceEncoder.init( this );
335  m_cCuEncoder.   init( this );
336 
337  // initialize transform & quantization class
338  m_pcCavlcCoder = getCavlcCoder();
339 
340  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
341                  m_useRDOQ, 
342                  m_useRDOQTS,
343                  true 
344                  ,m_useTransformSkipFast
345#if ADAPTIVE_QP_SELECTION                 
346                  , m_bUseAdaptQpSelect
347#endif
348                  );
349 
350  // initialize encoder search class
351  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
352
353  m_iMaxRefPicNum = 0;
354#if SVC_EXTENSION
355  m_iSPSIdCnt ++;
356  m_iPPSIdCnt ++;
357  xInitILRP();
358#endif
359}
360
361// ====================================================================================================================
362// Public member functions
363// ====================================================================================================================
364
365Void TEncTop::deletePicBuffer()
366{
367  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
368  Int iSize = Int( m_cListPic.size() );
369 
370  for ( Int i = 0; i < iSize; i++ )
371  {
372    TComPic* pcPic = *(iterPic++);
373   
374    pcPic->destroy();
375    delete pcPic;
376    pcPic = NULL;
377  }
378}
379
380/**
381 - Application has picture buffer list with size of GOP + 1
382 - Picture buffer list acts like as ring buffer
383 - End of the list has the latest picture
384 .
385 \param   flush               cause encoder to encode a partial GOP
386 \param   pcPicYuvOrg         original YUV picture
387 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
388 \retval  rcListBitstreamOut  list of output bitstreams
389 \retval  iNumEncoded         number of encoded pictures
390 */
391#if SVC_EXTENSION
392Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
393{
394  // compress GOP
395#if RATE_CONTROL_LAMBDA_DOMAIN
396#if !RC_SHVC_HARMONIZATION
397  if ( m_RCEnableRateControl )
398  {
399    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
400  }
401#endif
402#endif
403
404  // compress GOP
405  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
406
407#if RATE_CONTROL_LAMBDA_DOMAIN
408#if !RC_SHVC_HARMONIZATION
409  if ( m_RCEnableRateControl )
410  {
411    m_cRateCtrl.destroyRCGOP();
412  }
413#endif
414#endif
415 
416  m_uiNumAllPicCoded ++;
417}
418
419Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg )
420{
421  if (pcPicYuvOrg) 
422  {
423    // get original YUV
424    TComPic* pcPicCurr = NULL;
425    xGetNewPicBuffer( pcPicCurr );
426    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
427
428    // compute image characteristics
429    if ( getUseAdaptiveQP() )
430    {
431      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
432    }
433  }
434}
435#else
436Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
437{
438  if (pcPicYuvOrg) {
439    // get original YUV
440    TComPic* pcPicCurr = NULL;
441    xGetNewPicBuffer( pcPicCurr );
442    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
443
444    // compute image characteristics
445    if ( getUseAdaptiveQP() )
446    {
447      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
448    }
449  }
450 
451  if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
452  {
453    iNumEncoded = 0;
454    return;
455  }
456 
457#if RATE_CONTROL_LAMBDA_DOMAIN
458  if ( m_RCEnableRateControl )
459  {
460    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
461  }
462#endif
463
464  // compress GOP
465
466  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
467
468#if RATE_CONTROL_LAMBDA_DOMAIN
469  if ( m_RCEnableRateControl )
470  {
471    m_cRateCtrl.destroyRCGOP();
472  }
473#endif
474 
475  iNumEncoded         = m_iNumPicRcvd;
476  m_iNumPicRcvd       = 0;
477  m_uiNumAllPicCoded += iNumEncoded;
478}
479#endif
480
481/**------------------------------------------------
482 Separate interlaced frame into two fields
483 -------------------------------------------------**/
484void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
485{
486  if (!isTop)
487  {
488    org += stride;
489  }
490  for (Int y = 0; y < height>>1; y++)
491  {
492    for (Int x = 0; x < width; x++)
493    {
494      dstField[x] = org[x];
495    }
496   
497    dstField += stride;
498    org += stride*2;
499  }
500 
501}
502
503#if SVC_EXTENSION
504Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff )
505{
506  if (pcPicYuvOrg)
507  {
508    /* -- TOP FIELD -- */
509    /* -- Top field initialization -- */
510   
511    TComPic *pcTopField;
512    xGetNewPicBuffer( pcTopField );
513    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
514    pcTopField->setReconMark (false);
515   
516    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
517    pcTopField->getPicYuvRec()->setBorderExtension(false);
518    pcTopField->setTopField(isTff);
519   
520    Int nHeight = pcPicYuvOrg->getHeight();
521    Int nWidth = pcPicYuvOrg->getWidth();
522    Int nStride = pcPicYuvOrg->getStride();
523    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
524    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
525   
526    // Get pointers
527    Pel * PicBufY = pcPicYuvOrg->getBufY();
528    Pel * PicBufU = pcPicYuvOrg->getBufU();
529    Pel * PicBufV = pcPicYuvOrg->getBufV();
530   
531    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
532    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
533    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
534   
535    // compute image characteristics
536    if ( getUseAdaptiveQP() )
537    {
538      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
539    }
540   
541    /* -- Defield -- */
542   
543    Bool isTop = isTff;
544   
545    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
546    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
547    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
548
549    /* -- BOTTOM FIELD -- */
550    /* -- Bottom field initialization -- */
551   
552    TComPic* pcBottomField;
553    xGetNewPicBuffer( pcBottomField );
554    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
555    pcBottomField->setReconMark (false);
556   
557    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
558    pcBottomField->getPicYuvRec()->setBorderExtension(false);
559    pcBottomField->setTopField(!isTff);
560   
561    nHeight = pcPicYuvOrg->getHeight();
562    nWidth = pcPicYuvOrg->getWidth();
563    nStride = pcPicYuvOrg->getStride();
564    nPadLuma = pcPicYuvOrg->getLumaMargin();
565    nPadChroma = pcPicYuvOrg->getChromaMargin();
566   
567    // Get pointers
568    PicBufY = pcPicYuvOrg->getBufY();
569    PicBufU = pcPicYuvOrg->getBufU();
570    PicBufV = pcPicYuvOrg->getBufV();
571   
572    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
573    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
574    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
575   
576    // Compute image characteristics
577    if ( getUseAdaptiveQP() )
578    {
579      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
580    }
581   
582    /* -- Defield -- */
583   
584    isTop = !isTff;
585   
586    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
587    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
588    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
589   
590  }
591}
592
593Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
594{
595  // compress GOP
596  if (m_iPOCLast == 0) // compress field 0
597  {
598    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
599  }
600
601  if (pcPicYuvOrg)
602  {
603    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
604    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
605    {
606      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
607    }
608    else
609    {
610      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
611    }
612    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
613  }
614 
615  // compress GOP
616  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
617
618  m_uiNumAllPicCoded ++;
619}
620#else
621Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
622{
623  /* -- TOP FIELD -- */
624 
625  if (pcPicYuvOrg)
626  {
627   
628    /* -- Top field initialization -- */
629   
630    TComPic *pcTopField;
631    xGetNewPicBuffer( pcTopField );
632    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
633    pcTopField->setReconMark (false);
634   
635    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
636    pcTopField->getPicYuvRec()->setBorderExtension(false);
637    pcTopField->setTopField(isTff);
638   
639    Int nHeight = pcPicYuvOrg->getHeight();
640    Int nWidth = pcPicYuvOrg->getWidth();
641    Int nStride = pcPicYuvOrg->getStride();
642    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
643    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
644   
645    // Get pointers
646    Pel * PicBufY = pcPicYuvOrg->getBufY();
647    Pel * PicBufU = pcPicYuvOrg->getBufU();
648    Pel * PicBufV = pcPicYuvOrg->getBufV();
649   
650    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
651    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
652    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
653   
654    // compute image characteristics
655    if ( getUseAdaptiveQP() )
656    {
657      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
658    }
659   
660    /* -- Defield -- */
661   
662    Bool isTop = isTff;
663   
664    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
665    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
666    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
667   
668  }
669 
670  if (m_iPOCLast == 0) // compress field 0
671  {
672    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
673  }
674 
675  /* -- BOTTOM FIELD -- */
676 
677  if (pcPicYuvOrg)
678  {
679   
680    /* -- Bottom field initialization -- */
681   
682    TComPic* pcBottomField;
683    xGetNewPicBuffer( pcBottomField );
684    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
685    pcBottomField->setReconMark (false);
686   
687    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
688    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
689    {
690      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
691    }
692    else
693    {
694      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
695    }
696    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
697   
698    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
699    pcBottomField->getPicYuvRec()->setBorderExtension(false);
700    pcBottomField->setTopField(!isTff);
701   
702    int nHeight = pcPicYuvOrg->getHeight();
703    int nWidth = pcPicYuvOrg->getWidth();
704    int nStride = pcPicYuvOrg->getStride();
705    int nPadLuma = pcPicYuvOrg->getLumaMargin();
706    int nPadChroma = pcPicYuvOrg->getChromaMargin();
707   
708    // Get pointers
709    Pel * PicBufY = pcPicYuvOrg->getBufY();
710    Pel * PicBufU = pcPicYuvOrg->getBufU();
711    Pel * PicBufV = pcPicYuvOrg->getBufV();
712   
713    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
714    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
715    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
716   
717    // Compute image characteristics
718    if ( getUseAdaptiveQP() )
719    {
720      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
721    }
722   
723    /* -- Defield -- */
724   
725    Bool isTop = !isTff;
726   
727    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
728    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
729    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
730   
731  }
732 
733  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
734  {
735    iNumEncoded = 0;
736    return;
737  }
738 
739  // compress GOP
740  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
741 
742  iNumEncoded = m_iNumPicRcvd;
743  m_iNumPicRcvd = 0;
744  m_uiNumAllPicCoded += iNumEncoded;
745}
746#endif
747
748// ====================================================================================================================
749// Protected member functions
750// ====================================================================================================================
751
752/**
753 - Application has picture buffer list with size of GOP + 1
754 - Picture buffer list acts like as ring buffer
755 - End of the list has the latest picture
756 .
757 \retval rpcPic obtained picture buffer
758 */
759Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
760{
761  TComSlice::sortPicList(m_cListPic);
762 
763  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
764  {
765    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
766    Int iSize = Int( m_cListPic.size() );
767    for ( Int i = 0; i < iSize; i++ )
768    {
769      rpcPic = *(iterPic++);
770      if(rpcPic->getSlice(0)->isReferenced() == false)
771      {
772        break;
773      }
774    }
775  }
776  else
777  {
778    if ( getUseAdaptiveQP() )
779    {
780      TEncPic* pcEPic = new TEncPic;
781
782#if SVC_EXTENSION //Temporal solution, should be modified
783      if(m_layerId > 0)
784      {
785        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
786        {
787          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
788          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
789
790#if VPS_EXTN_DIRECT_REF_LAYERS
791          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
792#else
793          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
794#endif
795          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
796          {
797            pcEPic->setSpatialEnhLayerFlag( i, true );
798
799            //only for scalable extension
800#if SCALABILITY_MASK_E0104
801            assert( m_cVPS.getScalabilityMask(2) == true );
802#else
803            assert( m_cVPS.getScalabilityMask(1) == true );
804#endif
805          }
806        }
807      }
808#endif
809
810#if SVC_UPSAMPLING
811      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
812                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
813#else
814      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
815                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
816#endif
817      rpcPic = pcEPic;
818    }
819    else
820    {
821      rpcPic = new TComPic;
822
823#if SVC_EXTENSION //Temporal solution, should be modified
824      if(m_layerId > 0)
825      {
826        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
827        {
828          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
829          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
830
831#if VPS_EXTN_DIRECT_REF_LAYERS
832          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
833#else
834          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
835#endif
836          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
837          {
838            rpcPic->setSpatialEnhLayerFlag( i, true );
839
840            //only for scalable extension
841#if SCALABILITY_MASK_E0104
842            assert( m_cVPS.getScalabilityMask(2) == true );
843#else
844            assert( m_cVPS.getScalabilityMask(1) == true );
845#endif
846          }
847        }
848      }
849#endif
850
851#if SVC_UPSAMPLING
852      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
853                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
854#else
855      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
856                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
857#endif
858    }
859
860    if (getUseSAO())
861    {
862      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
863    }
864    m_cListPic.pushBack( rpcPic );
865  }
866  rpcPic->setReconMark (false);
867 
868  m_iPOCLast++;
869  m_iNumPicRcvd++;
870 
871  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
872  // mark it should be extended
873  rpcPic->getPicYuvRec()->setBorderExtension(false);
874}
875
876Void TEncTop::xInitSPS()
877{
878#if SVC_EXTENSION
879  m_cSPS.setLayerId(m_layerId);
880#endif
881#if REF_IDX_MFM
882#if !M0457_COL_PICTURE_SIGNALING
883  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
884#endif
885#endif
886#if SCALED_REF_LAYER_OFFSETS
887  m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
888  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
889  {
890    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
891  }
892#endif
893  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
894  profileTierLevel.setLevelIdc(m_level);
895  profileTierLevel.setTierFlag(m_levelTier);
896  profileTierLevel.setProfileIdc(m_profile);
897  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
898  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
899  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
900  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
901  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
902 
903  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
904  {
905    /* The above constraint is equal to Profile::MAIN */
906    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
907  }
908  if (m_profile == Profile::MAIN)
909  {
910    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
911    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
912  }
913  /* XXX: should Main be marked as compatible with still picture? */
914  /* XXX: may be a good idea to refactor the above into a function
915   * that chooses the actual compatibility based upon options */
916
917  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
918  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
919  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
920  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
921  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
922  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
923
924  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
925  Int log2MinCUSize = 0;
926  while(minCUSize > 1)
927  {
928    minCUSize >>= 1;
929    log2MinCUSize++;
930  }
931
932  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
933  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth);
934#if SVC_EXTENSION
935  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
936#endif
937 
938  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
939  m_cSPS.setUsePCM        ( m_usePCM           );
940  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
941
942  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
943  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
944  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
945  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
946 
947  m_cSPS.setTMVPFlagsPresent(false);
948  m_cSPS.setUseLossless   ( m_useLossless  );
949
950  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
951 
952  Int i;
953 
954  for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ )
955  {
956    m_cSPS.setAMPAcc( i, m_useAMP );
957    //m_cSPS.setAMPAcc( i, 1 );
958  }
959
960  m_cSPS.setUseAMP ( m_useAMP );
961
962  for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ )
963  {
964    m_cSPS.setAMPAcc(i, 0);
965  }
966
967#if REPN_FORMAT_IN_VPS
968  m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() );
969  m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  );
970
971  m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma()  - 8) );
972  m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  - 8) );
973#else
974  m_cSPS.setBitDepthY( g_bitDepthY );
975  m_cSPS.setBitDepthC( g_bitDepthC );
976
977  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
978  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
979#endif
980
981  m_cSPS.setUseSAO( m_bUseSAO );
982
983  m_cSPS.setMaxTLayers( m_maxTempLayer );
984  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
985  for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
986  {
987    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
988    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
989  }
990  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
991  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
992  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
993
994  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
995
996  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
997
998  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
999  if (m_cSPS.getVuiParametersPresentFlag())
1000  {
1001    TComVUI* pcVUI = m_cSPS.getVuiParameters();
1002    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1);
1003    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
1004    pcVUI->setSarWidth(getSarWidth());
1005    pcVUI->setSarHeight(getSarHeight());
1006    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
1007    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
1008    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
1009    pcVUI->setVideoFormat(getVideoFormat());
1010    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
1011    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
1012    pcVUI->setColourPrimaries(getColourPrimaries());
1013    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
1014    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
1015    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
1016    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
1017    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
1018    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
1019    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
1020    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
1021    pcVUI->setFieldSeqFlag(false);
1022    pcVUI->setHrdParametersPresentFlag(false);
1023    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
1024    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
1025    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
1026    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
1027    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
1028    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
1029    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
1030    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
1031    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
1032    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
1033  }
1034}
1035
1036Void TEncTop::xInitPPS()
1037{
1038#if IL_SL_SIGNALLING_N0371
1039  m_cPPS.setLayerId(m_layerId);
1040#endif
1041
1042  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1043  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1044
1045#if REPN_FORMAT_IN_VPS
1046  Int lowestQP;
1047  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
1048  {
1049    lowestQP = - m_cSPS.getQpBDOffsetY();
1050  }
1051  else
1052  {
1053    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
1054  }
1055#else
1056  Int lowestQP = - m_cSPS.getQpBDOffsetY();
1057#endif
1058
1059  if(getUseLossless())
1060  {
1061    if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )
1062    {
1063      bUseDQP = false;
1064    }
1065    else
1066    {
1067      bUseDQP = true;
1068    }
1069  }
1070  else
1071  {
1072    if(bUseDQP == false)
1073    {
1074      if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1075      {
1076        bUseDQP = true;
1077      }
1078    }
1079  }
1080
1081  if(bUseDQP)
1082  {
1083    m_cPPS.setUseDQP(true);
1084    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1085    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1086  }
1087  else
1088  {
1089    m_cPPS.setUseDQP(false);
1090    m_cPPS.setMaxCuDQPDepth( 0 );
1091    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1092  }
1093
1094#if RATE_CONTROL_LAMBDA_DOMAIN
1095  if ( m_RCEnableRateControl )
1096  {
1097    m_cPPS.setUseDQP(true);
1098    m_cPPS.setMaxCuDQPDepth( 0 );
1099    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1100  } 
1101#endif
1102
1103  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
1104  m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset );
1105
1106  m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams);
1107  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1108  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1109  m_cPPS.setUseWP( m_useWeightedPred );
1110  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1111  m_cPPS.setOutputFlagPresentFlag( false );
1112  m_cPPS.setSignHideFlag(getSignHideFlag());
1113  if ( getDeblockingFilterMetric() )
1114  {
1115    m_cPPS.setDeblockingFilterControlPresentFlag (true);
1116    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1117    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1118    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1119    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1120  } 
1121  else
1122  {
1123  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
1124  }
1125  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1126  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1127  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1128  Int histogram[MAX_NUM_REF + 1];
1129  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1130  {
1131    histogram[i]=0;
1132  }
1133  for( Int i = 0; i < getGOPSize(); i++ )
1134  {
1135    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1136    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1137  }
1138  Int maxHist=-1;
1139  Int bestPos=0;
1140  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1141  {
1142    if(histogram[i]>maxHist)
1143    {
1144      maxHist=histogram[i];
1145      bestPos=i;
1146    }
1147  }
1148  assert(bestPos <= 15);
1149  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1150  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1151  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1152  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1153  if (m_sliceSegmentMode)
1154  {
1155    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1156  }
1157  if( m_cPPS.getDependentSliceSegmentsEnabledFlag() )
1158  {
1159    Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1;
1160    m_cSliceEncoder.initCtxMem( NumCtx );
1161    for ( UInt st = 0; st < NumCtx; st++ )
1162    {
1163      TEncSbac* ctx = NULL;
1164      ctx = new TEncSbac;
1165      ctx->init( &m_cBinCoderCABAC );
1166      m_cSliceEncoder.setCtxMem( ctx, st );
1167    }
1168  }
1169#if SVC_EXTENSION
1170  if (!m_layerId)
1171  {
1172    m_cPPS.setListsModificationPresentFlag(false);
1173  }
1174  else
1175  {
1176    m_cPPS.setListsModificationPresentFlag(true);
1177  }
1178
1179  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
1180  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
1181#endif
1182#if POC_RESET_FLAG
1183  m_cPPS.setNumExtraSliceHeaderBits( 2 );
1184#endif
1185}
1186
1187//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1188Void TEncTop::xInitRPS(Bool isFieldCoding)
1189{
1190  TComReferencePictureSet*      rps;
1191 
1192  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
1193  TComRPSList* rpsList = m_cSPS.getRPSList();
1194
1195  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
1196  {
1197#if FINAL_RPL_CHANGE_N0082
1198    GOPEntry ge = m_ppcTEncTop[m_cSPS.getLayerId()]->getGOPEntry(i);
1199#else
1200    GOPEntry ge = getGOPEntry(i);
1201#endif
1202    rps = rpsList->getReferencePictureSet(i);
1203    rps->setNumberOfPictures(ge.m_numRefPics);
1204    rps->setNumRefIdc(ge.m_numRefIdc);
1205    Int numNeg = 0;
1206    Int numPos = 0;
1207    for( Int j = 0; j < ge.m_numRefPics; j++)
1208    {
1209      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1210      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1211      if(ge.m_referencePics[j]>0)
1212      {
1213        numPos++;
1214      }
1215      else
1216      {
1217        numNeg++;
1218      }
1219    }
1220    rps->setNumberOfNegativePictures(numNeg);
1221    rps->setNumberOfPositivePictures(numPos);
1222
1223    // handle inter RPS intialization from the config file.
1224#if AUTO_INTER_RPS
1225    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1226    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1227    TComReferencePictureSet*     RPSRef = rpsList->getReferencePictureSet(i-1);  // get the reference RPS
1228
1229    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1230    {
1231      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1232      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1233
1234      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1235      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1236      Int count=0;
1237      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1238      {
1239        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1240        rps->setRefIdc(j, 0);
1241        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1242        {
1243          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1244          {
1245              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1246              count++;
1247              break;
1248          }
1249        }
1250      }
1251      if (count != rps->getNumberOfPictures())
1252      {
1253        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");
1254        rps->setInterRPSPrediction(0);
1255      }
1256    }
1257    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1258    {
1259      rps->setDeltaRPS(ge.m_deltaRPS);
1260      rps->setNumRefIdc(ge.m_numRefIdc);
1261      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1262      {
1263        rps->setRefIdc(j, ge.m_refIdc[j]);
1264      }
1265#if WRITE_BACK
1266      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1267      // computed from the RefIdc.  A warning is printed if they are not identical.
1268      numNeg = 0;
1269      numPos = 0;
1270      TComReferencePictureSet      RPSTemp;  // temporary variable
1271
1272      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1273      {
1274        if (ge.m_refIdc[j])
1275        {
1276          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1277          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1278          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1279          if (deltaPOC<0)
1280          {
1281            numNeg++;
1282          }
1283          else
1284          {
1285            numPos++;
1286          }
1287        }
1288      }
1289      if (numNeg != rps->getNumberOfNegativePictures())
1290      {
1291        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1292        rps->setNumberOfNegativePictures(numNeg);
1293        rps->setNumberOfPictures(numNeg+numPos);
1294      }
1295      if (numPos != rps->getNumberOfPositivePictures())
1296      {
1297        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1298        rps->setNumberOfPositivePictures(numPos);
1299        rps->setNumberOfPictures(numNeg+numPos);
1300      }
1301      RPSTemp.setNumberOfPictures(numNeg+numPos);
1302      RPSTemp.setNumberOfNegativePictures(numNeg);
1303      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1304      // check if Delta POC and Used are the same
1305      // print warning if they are not.
1306      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1307      {
1308        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1309        {
1310          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1311          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1312        }
1313        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1314        {
1315          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1316          rps->setUsed(j,RPSTemp.getUsed(j));
1317        }
1318      }
1319#endif
1320    }
1321#else
1322    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
1323    if (ge.m_interRPSPrediction)
1324    {
1325      rps->setDeltaRIdxMinus1(0);
1326      rps->setDeltaRPS(ge.m_deltaRPS);
1327      rps->setNumRefIdc(ge.m_numRefIdc);
1328      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1329      {
1330        rps->setRefIdc(j, ge.m_refIdc[j]);
1331      }
1332#if WRITE_BACK
1333      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1334      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
1335      numNeg = 0;
1336      numPos = 0;
1337      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
1338
1339      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1340      {
1341        if (ge.m_refIdc[j])
1342        {
1343          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1344          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
1345          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1346          if (deltaPOC<0)
1347          {
1348            numNeg++;
1349          }
1350          else
1351          {
1352            numPos++;
1353          }
1354        }
1355      }
1356      rps->setNumberOfNegativePictures(numNeg);
1357      rps->setNumberOfPositivePictures(numPos);
1358      rps->sortDeltaPOC();
1359#endif
1360    }
1361#endif //INTER_RPS_AUTO
1362  }
1363  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
1364  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1365  if (isFieldCoding) 
1366  {
1367    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1368    rps->setNumberOfPictures(1);
1369    rps->setNumberOfNegativePictures(1);
1370    rps->setNumberOfPositivePictures(0);
1371    rps->setNumberOfLongtermPictures(0);
1372    rps->setDeltaPOC(0,-1);
1373    rps->setPOC(0,0);
1374    rps->setUsed(0,true);
1375    rps->setInterRPSPrediction(false);
1376    rps->setDeltaRIdxMinus1(0);
1377    rps->setDeltaRPS(0);
1378    rps->setNumRefIdc(0);
1379}
1380}
1381
1382   // This is a function that
1383   // determines what Reference Picture Set to use
1384   // for a specific slice (with POC = POCCurr)
1385Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1386{
1387  slice->setRPSidx(GOPid);
1388  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1389  {   
1390    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1391    {
1392      Int POCIndex = POCCurr%m_uiIntraPeriod;
1393      if(POCIndex == 0)
1394      {
1395        POCIndex = m_uiIntraPeriod;
1396      }
1397      if(POCIndex == m_GOPList[extraNum].m_POC)
1398      {
1399        slice->setRPSidx(extraNum);
1400      }
1401    }
1402    else
1403    {
1404      if(POCCurr==m_GOPList[extraNum].m_POC)
1405      {
1406        slice->setRPSidx(extraNum);
1407      }
1408    }
1409  }
1410
1411  if(POCCurr == 1 && slice->getPic()->isField())
1412  {
1413    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1414  }
1415
1416  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1417  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1418}
1419
1420Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
1421{
1422  int rpsIdx = GOPid;
1423
1424  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1425  {   
1426    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1427    {
1428      Int POCIndex = POCCurr%m_uiIntraPeriod;
1429      if(POCIndex == 0)
1430      {
1431        POCIndex = m_uiIntraPeriod;
1432      }
1433      if(POCIndex == m_GOPList[extraNum].m_POC)
1434      {
1435        rpsIdx = extraNum;
1436      }
1437    }
1438    else
1439    {
1440      if(POCCurr==m_GOPList[extraNum].m_POC)
1441      {
1442        rpsIdx = extraNum;
1443      }
1444    }
1445  }
1446
1447  return rpsIdx;
1448}
1449
1450Void  TEncTop::xInitPPSforTiles()
1451{
1452  m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr );
1453  m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
1454  m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
1455  if( m_iUniformSpacingIdr == 0 )
1456  {
1457    m_cPPS.setColumnWidth( m_puiColumnWidth );
1458    m_cPPS.setRowHeight( m_puiRowHeight );
1459  }
1460  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1461
1462  // # substreams is "per tile" when tiles are independent.
1463  if (m_iWaveFrontSynchro
1464    )
1465  {
1466    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
1467  }
1468}
1469
1470Void  TEncCfg::xCheckGSParameters()
1471{
1472  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1473  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1474  UInt  uiCummulativeColumnWidth = 0;
1475  UInt  uiCummulativeRowHeight = 0;
1476
1477  //check the column relative parameters
1478  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1479  {
1480    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1481    exit( EXIT_FAILURE );
1482  }
1483
1484  if( m_iNumColumnsMinus1 >= iWidthInCU )
1485  {
1486    printf( "The current picture can not have so many columns.\n" );
1487    exit( EXIT_FAILURE );
1488  }
1489
1490  if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
1491  {
1492    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1493    {
1494      uiCummulativeColumnWidth += m_puiColumnWidth[i];
1495    }
1496
1497    if( uiCummulativeColumnWidth >= iWidthInCU )
1498    {
1499      printf( "The width of the column is too large.\n" );
1500      exit( EXIT_FAILURE );
1501    }
1502  }
1503
1504  //check the row relative parameters
1505  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1506  {
1507    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1508    exit( EXIT_FAILURE );
1509  }
1510
1511  if( m_iNumRowsMinus1 >= iHeightInCU )
1512  {
1513    printf( "The current picture can not have so many rows.\n" );
1514    exit( EXIT_FAILURE );
1515  }
1516
1517  if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
1518  {
1519    for(Int i=0; i<m_iNumRowsMinus1; i++)
1520    {
1521      uiCummulativeRowHeight += m_puiRowHeight[i];
1522    }
1523
1524    if( uiCummulativeRowHeight >= iHeightInCU )
1525    {
1526      printf( "The height of the row is too large.\n" );
1527      exit( EXIT_FAILURE );
1528    }
1529  }
1530}
1531
1532#if SVC_EXTENSION
1533#if VPS_EXTN_DIRECT_REF_LAYERS
1534TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc )
1535{
1536  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
1537  {
1538    return (TEncTop *)getLayerEnc( 0 );
1539  }
1540
1541  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) );
1542}
1543#endif
1544
1545#if SVC_EXTENSION
1546#if !REPN_FORMAT_IN_VPS
1547Void TEncTop::xInitILRP()
1548{
1549  if(m_layerId>0)
1550  {
1551    g_bitDepthY     = m_cSPS.getBitDepthY();
1552    g_bitDepthC     = m_cSPS.getBitDepthC();
1553    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1554    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1555    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1556    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1557
1558    Int  numReorderPics[MAX_TLAYER];
1559    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1560    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1561
1562    if (m_cIlpPic[0] == NULL)
1563    {
1564      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
1565      {
1566        m_cIlpPic[j] = new  TComPic;
1567#if SVC_UPSAMPLING
1568        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1569#else
1570        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
1571#endif
1572        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1573        {
1574          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1575        }
1576      }
1577    }
1578  }
1579}
1580#else
1581Void TEncTop::xInitILRP()
1582{
1583  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
1584  Int bitDepthY,bitDepthC,picWidth,picHeight;
1585
1586  if( m_cSPS.getUpdateRepFormatFlag() )
1587  {
1588    bitDepthY   = m_cSPS.getBitDepthY();
1589    bitDepthC   = m_cSPS.getBitDepthC();
1590    picWidth    = m_cSPS.getPicWidthInLumaSamples();
1591    picHeight   = m_cSPS.getPicHeightInLumaSamples();
1592  }
1593  else
1594  {
1595    bitDepthY   = repFormat->getBitDepthVpsLuma();
1596    bitDepthC   = repFormat->getBitDepthVpsChroma();
1597    picWidth    = repFormat->getPicWidthVpsInLumaSamples();
1598    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
1599  }
1600 
1601  if(m_layerId > 0)
1602  {
1603    g_bitDepthY     = bitDepthY;
1604    g_bitDepthC     = bitDepthC;
1605    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1606    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1607    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1608    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1609
1610    Int  numReorderPics[MAX_TLAYER];
1611    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1612    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1613
1614    if (m_cIlpPic[0] == NULL)
1615    {
1616      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
1617      {
1618        m_cIlpPic[j] = new  TComPic;
1619#if SVC_UPSAMPLING
1620        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1621#else
1622        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
1623#endif
1624        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1625        {
1626          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1627        }
1628      }
1629    }
1630  }
1631}
1632#endif
1633Void TEncTop::setILRPic(TComPic *pcPic)
1634{
1635  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
1636  {
1637    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
1638
1639    if(m_cIlpPic[refLayerIdc])
1640    {
1641      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
1642      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
1643      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
1644      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
1645      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
1646      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
1647      {
1648        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
1649      }
1650    }
1651  }
1652}
1653#endif
1654#endif
1655//! \}
Note: See TracBrowser for help on using the repository browser.