source: SHVCSoftware/branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 520

Last change on this file since 520 was 507, checked in by nokia, 12 years ago

Add scaled reference layer ID (JCTVC-O0098)

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