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

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

initial porting of HM12

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