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

Last change on this file since 1242 was 1235, checked in by seregin, 9 years ago

port rev 4219 and rev 4246

  • Property svn:eol-style set to native
File size: 56.1 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-2014, 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#include "TLibCommon/TComChromaFormat.h"
42#if FAST_BIT_EST
43#include "TLibCommon/ContextModel.h"
44#endif
45
46//! \ingroup TLibEncoder
47//! \{
48#if SVC_EXTENSION 
49Int TEncTop::m_iSPSIdCnt = 0;
50Int TEncTop::m_iPPSIdCnt = 0;
51TComVPS TEncCfg::m_cVPS;
52#endif
53
54// ====================================================================================================================
55// Constructor / destructor / create / destroy
56// ====================================================================================================================
57
58TEncTop::TEncTop()
59{
60  m_iPOCLast          = -1;
61  m_iNumPicRcvd       =  0;
62  m_uiNumAllPicCoded  =  0;
63  m_pppcRDSbacCoder   =  NULL;
64  m_pppcBinCoderCABAC =  NULL;
65  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
66#if ENC_DEC_TRACE
67  if (g_hTrace == NULL)
68  {
69    g_hTrace = fopen( "TraceEnc.txt", "wb" );
70  }
71  g_bJustDoIt = g_bEncDecTraceDisable;
72  g_nSymbolCounter = 0;
73#endif
74
75  m_iMaxRefPicNum     = 0;
76
77#if FAST_BIT_EST
78  ContextModel::buildNextStateTable();
79#endif
80
81#if SVC_EXTENSION
82  memset( m_cIlpPic, 0, sizeof(m_cIlpPic) );
83  m_bMFMEnabledFlag = false;
84  m_numRefLayerLocationOffsets = 0;
85  m_pocAdjustmentValue     = 0;
86#if NO_CLRAS_OUTPUT_FLAG
87  m_noClrasOutputFlag          = false;
88  m_layerInitializedFlag       = false;
89  m_firstPicInLayerDecodedFlag = false;
90  m_noOutputOfPriorPicsFlags   = false;
91#endif
92  m_pocDecrementedInDPBFlag    = false;
93#endif //SVC_EXTENSION
94}
95
96TEncTop::~TEncTop()
97{
98#if ENC_DEC_TRACE
99  if (g_hTrace != stdout)
100  {
101    fclose( g_hTrace );
102  }
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(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
120  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, m_chromaFormatIDC );
121  if (m_bUseSAO)
122  {
123    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA], m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA] );
124#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
125    m_cEncSAO.createEncData(getSaoCtuBoundary());
126#else
127    m_cEncSAO.createEncData();
128#endif
129  }
130#if ADAPTIVE_QP_SELECTION
131  if (m_bUseAdaptQpSelect)
132  {
133    m_cTrQuant.initSliceQpDelta();
134  }
135#endif
136
137  m_cLoopFilter.create( g_uiMaxCUDepth );
138
139  if ( m_RCEnableRateControl )
140  {
141    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
142                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
143  }
144
145  m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
146#if FAST_BIT_EST
147  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
148#else
149  m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
150#endif
151
152  for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
153  {
154    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
155#if FAST_BIT_EST
156    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
157#else
158    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
159#endif
160
161    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
162    {
163      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
164#if FAST_BIT_EST
165      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
166#else
167      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
168#endif
169      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
170    }
171  }
172
173#if LAYER_CTB
174  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
175  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
176  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
177  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
178#endif
179}
180
181Void TEncTop::destroy ()
182{
183  // destroy processing unit classes
184  m_cGOPEncoder.        destroy();
185  m_cSliceEncoder.      destroy();
186  m_cCuEncoder.         destroy();
187  m_cEncSAO.            destroyEncData();
188  m_cEncSAO.            destroy();
189  m_cLoopFilter.        destroy();
190  m_cRateCtrl.          destroy();
191  Int iDepth;
192  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
193  {
194    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
195    {
196      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
197      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
198    }
199  }
200
201  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
202  {
203    delete [] m_pppcRDSbacCoder[iDepth];
204    delete [] m_pppcBinCoderCABAC[iDepth];
205  }
206
207  delete [] m_pppcRDSbacCoder;
208  delete [] m_pppcBinCoderCABAC;
209 
210#if SVC_EXTENSION
211  for(Int i=0; i<MAX_NUM_REF; i++)
212  {
213    if(m_cIlpPic[i])
214    {
215      m_cIlpPic[i]->destroy();
216      delete m_cIlpPic[i];
217      m_cIlpPic[i] = NULL;
218    }
219  }
220#else
221  // destroy ROM
222  destroyROM();
223#endif
224  return;
225}
226
227Void TEncTop::init(Bool isFieldCoding)
228{
229  // initialize SPS
230  xInitSPS();
231  xInitVPS();
232
233  m_cRdCost.setCostMode(m_costMode);
234
235  // initialize PPS
236  xInitPPS();
237  xInitRPS(isFieldCoding);
238
239  xInitPPSforTiles();
240
241  // initialize processing unit classes
242  m_cGOPEncoder.  init( this );
243  m_cSliceEncoder.init( this );
244  m_cCuEncoder.   init( this );
245
246  // initialize transform & quantization class
247  m_pcCavlcCoder = getCavlcCoder();
248
249  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
250                   m_useRDOQ,
251                   m_useRDOQTS,
252                   true
253                  ,m_useTransformSkipFast
254#if ADAPTIVE_QP_SELECTION
255                  ,m_bUseAdaptQpSelect
256#endif
257                  );
258
259  // initialize encoder search class
260  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
261
262  m_iMaxRefPicNum = 0;
263
264  xInitScalingLists();
265
266#if SVC_EXTENSION
267  m_iSPSIdCnt ++;
268  m_iPPSIdCnt ++;
269  xInitILRP();
270#endif
271}
272
273Void TEncTop::xInitScalingLists()
274{
275  // Initialise scaling lists
276  // The encoder will only use the SPS scaling lists. The PPS will never be marked present.
277
278  if(getUseScalingListId() == SCALING_LIST_OFF)
279  {
280#if SVC_EXTENSION
281    getTrQuant()->setFlatScalingList(m_cVPS.getChromaFormatIdc(&m_cSPS, m_layerId));
282#else
283    getTrQuant()->setFlatScalingList(m_cSPS.getChromaFormatIdc());
284#endif
285    getTrQuant()->setUseScalingList(false);
286    m_cSPS.setScalingListPresentFlag(false);
287    m_cPPS.setScalingListPresentFlag(false);
288  }
289  else if(getUseScalingListId() == SCALING_LIST_DEFAULT)
290  {
291#if SVC_EXTENSION
292    // inferring of the scaling list can be moved to the config file
293    UInt refLayerId = 0;
294    if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
295    {
296      m_cSPS.setInferScalingListFlag( true );
297      m_cSPS.setScalingListRefLayerId( refLayerId );
298      m_cSPS.setScalingListPresentFlag( false );
299      m_cPPS.setInferScalingListFlag( false );
300      m_cPPS.setScalingListPresentFlag( false );
301
302      // infer the scaling list from the reference layer
303      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() );
304    }
305    else
306    {
307#endif
308    m_cSPS.getScalingList().setDefaultScalingList ();
309    m_cSPS.setScalingListPresentFlag(false);
310    m_cPPS.setScalingListPresentFlag(false);
311    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc());
312#if SVC_EXTENSION
313    }
314#endif
315    getTrQuant()->setUseScalingList(true);
316  }
317  else if(getUseScalingListId() == SCALING_LIST_FILE_READ)
318  {
319#if SVC_EXTENSION
320    // inferring of the scaling list can be moved to the config file
321    UInt refLayerId = 0;
322    if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
323    {
324      m_cSPS.setInferScalingListFlag( true );
325      m_cSPS.setScalingListRefLayerId( refLayerId );
326      m_cSPS.setScalingListPresentFlag( false );
327      m_cPPS.setInferScalingListFlag( false );
328      m_cPPS.setScalingListPresentFlag( false );
329
330      // infer the scaling list from the reference layer
331      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() );
332    }
333    else
334    {
335#endif
336    m_cSPS.getScalingList().setDefaultScalingList ();
337    if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile()))
338    {
339      Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string
340      assert(bParsedScalingList);
341      exit(1);
342    }
343    m_cSPS.getScalingList().checkDcOfMatrix();
344    m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList());
345    m_cPPS.setScalingListPresentFlag(false);
346    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc());
347#if SVC_EXTENSION
348    }
349#endif
350    getTrQuant()->setUseScalingList(true);
351  }
352  else
353  {
354    printf("error : ScalingList == %d not supported\n",getUseScalingListId());
355    assert(0);
356  }
357
358  // Prepare delta's:
359  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
360  {
361    const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
362
363    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep)
364    {
365      m_cSPS.getScalingList().checkPredMode( sizeId, listId );
366    }
367  }
368
369}
370
371// ====================================================================================================================
372// Public member functions
373// ====================================================================================================================
374
375Void TEncTop::deletePicBuffer()
376{
377  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
378  Int iSize = Int( m_cListPic.size() );
379
380  for ( Int i = 0; i < iSize; i++ )
381  {
382    TComPic* pcPic = *(iterPic++);
383
384    pcPic->destroy();
385    delete pcPic;
386    pcPic = NULL;
387  }
388}
389
390/**
391 - Application has picture buffer list with size of GOP + 1
392 - Picture buffer list acts like as ring buffer
393 - End of the list has the latest picture
394 .
395 \param   flush               cause encoder to encode a partial GOP
396 \param   pcPicYuvOrg         original YUV picture
397 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
398 \retval  rcListBitstreamOut  list of output bitstreams
399 \retval  iNumEncoded         number of encoded pictures
400 */
401#if SVC_EXTENSION
402Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
403{
404  // compress GOP
405#if !RC_SHVC_HARMONIZATION
406  if ( m_RCEnableRateControl )
407  {
408    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
409  }
410#endif
411
412  // compress GOP
413  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
414
415#if !RC_SHVC_HARMONIZATION
416  if ( m_RCEnableRateControl )
417  {
418    m_cRateCtrl.destroyRCGOP();
419  }
420#endif
421 
422  m_uiNumAllPicCoded ++;
423}
424
425Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg )
426{
427  if (pcPicYuvOrg != NULL)
428  {
429    // get original YUV
430    TComPic* pcPicCurr = NULL;
431    xGetNewPicBuffer( pcPicCurr );
432    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
433    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
434
435    // compute image characteristics
436    if ( getUseAdaptiveQP() )
437    {
438      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
439    }
440  }
441}
442#else
443Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
444{
445  if (pcPicYuvOrg != NULL)
446  {
447    // get original YUV
448    TComPic* pcPicCurr = NULL;
449
450    xGetNewPicBuffer( pcPicCurr );
451    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
452    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
453
454    // compute image characteristics
455    if ( getUseAdaptiveQP() )
456    {
457      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
458    }
459  }
460
461  if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0)))
462  {
463    iNumEncoded = 0;
464    return;
465  }
466
467  if ( m_RCEnableRateControl )
468  {
469    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
470  }
471
472  // compress GOP
473  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
474
475  if ( m_RCEnableRateControl )
476  {
477    m_cRateCtrl.destroyRCGOP();
478  }
479
480  iNumEncoded         = m_iNumPicRcvd;
481  m_iNumPicRcvd       = 0;
482  m_uiNumAllPicCoded += iNumEncoded;
483}
484#endif
485
486/**------------------------------------------------
487 Separate interlaced frame into two fields
488 -------------------------------------------------**/
489Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
490{
491  if (!isTop)
492  {
493    org += stride;
494  }
495  for (Int y = 0; y < height>>1; y++)
496  {
497    for (Int x = 0; x < width; x++)
498    {
499      dstField[x] = org[x];
500    }
501
502    dstField += stride;
503    org += stride*2;
504  }
505
506}
507
508#if SVC_EXTENSION
509Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff )
510{
511  for (Int fieldNum=0; fieldNum<2; fieldNum++)
512  {
513    if (pcPicYuvOrg)
514    {
515      /* -- field initialization -- */
516      const Bool isTopField=isTff==(fieldNum==0);
517
518      TComPic *pcField;
519      xGetNewPicBuffer( pcField );
520      pcField->setReconMark (false);                     // where is this normally?
521           
522      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
523      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
524
525      pcField->setTopField(isTopField);                  // interlaced requirement
526
527      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
528      {
529        const ComponentID component = ComponentID(componentIndex);
530        const UInt stride = pcPicYuvOrg->getStride(component);
531
532        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
533                       pcField->getPicYuvOrg()->getAddr(component),
534                       pcPicYuvOrg->getStride(component),
535                       pcPicYuvOrg->getWidth(component),
536                       pcPicYuvOrg->getHeight(component),
537                       isTopField);
538
539        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
540                       pcField->getPicYuvTrueOrg()->getAddr(component),
541                       pcPicYuvTrueOrg->getStride(component),
542                       pcPicYuvTrueOrg->getWidth(component),
543                       pcPicYuvTrueOrg->getHeight(component),
544                       isTopField);
545      }
546
547      // compute image characteristics
548      if ( getUseAdaptiveQP() )
549      {
550        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
551      }
552    }
553  }
554}
555
556Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
557{
558  for (Int fieldNum=0; fieldNum<2; fieldNum++)
559  {
560    if (pcPicYuvOrg)
561    {
562      if (fieldNum==1)                                   // where is this normally?
563      {
564        TComPicYuv* rpcPicYuvRec;
565
566        // org. buffer
567        if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize.
568        {
569          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
570        }
571        else
572        {
573          rpcPicYuvRec = new TComPicYuv;
574          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
575        }
576        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
577      }
578    }
579
580    // compress GOP
581    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
582  }
583
584  m_uiNumAllPicCoded ++;
585}
586#else
587Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
588{
589  iNumEncoded = 0;
590
591  for (Int fieldNum=0; fieldNum<2; fieldNum++)
592  {
593    if (pcPicYuvOrg)
594    {
595
596      /* -- field initialization -- */
597      const Bool isTopField=isTff==(fieldNum==0);
598
599      TComPic *pcField;
600      xGetNewPicBuffer( pcField );
601      pcField->setReconMark (false);                     // where is this normally?
602
603      if (fieldNum==1)                                   // where is this normally?
604      {
605        TComPicYuv* rpcPicYuvRec;
606
607        // org. buffer
608        if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize.
609        {
610          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
611        }
612        else
613        {
614          rpcPicYuvRec = new TComPicYuv;
615          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
616        }
617        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
618      }
619
620      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
621      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
622
623      pcField->setTopField(isTopField);                  // interlaced requirement
624
625      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
626      {
627        const ComponentID component = ComponentID(componentIndex);
628        const UInt stride = pcPicYuvOrg->getStride(component);
629
630        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
631                       pcField->getPicYuvOrg()->getAddr(component),
632                       pcPicYuvOrg->getStride(component),
633                       pcPicYuvOrg->getWidth(component),
634                       pcPicYuvOrg->getHeight(component),
635                       isTopField);
636
637        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
638                       pcField->getPicYuvTrueOrg()->getAddr(component),
639                       pcPicYuvTrueOrg->getStride(component),
640                       pcPicYuvTrueOrg->getWidth(component),
641                       pcPicYuvTrueOrg->getHeight(component),
642                       isTopField);
643      }
644
645      // compute image characteristics
646      if ( getUseAdaptiveQP() )
647      {
648        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
649      }
650    }
651
652    if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
653    {
654      // compress GOP
655      m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
656
657      iNumEncoded += m_iNumPicRcvd;
658      m_uiNumAllPicCoded += m_iNumPicRcvd;
659      m_iNumPicRcvd = 0;
660    }
661  }
662}
663#endif
664
665// ====================================================================================================================
666// Protected member functions
667// ====================================================================================================================
668
669/**
670 - Application has picture buffer list with size of GOP + 1
671 - Picture buffer list acts like as ring buffer
672 - End of the list has the latest picture
673 .
674 \retval rpcPic obtained picture buffer
675 */
676Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
677{
678  // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
679
680  TComSlice::sortPicList(m_cListPic);
681
682  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
683  {
684    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
685    Int iSize = Int( m_cListPic.size() );
686    for ( Int i = 0; i < iSize; i++ )
687    {
688      rpcPic = *(iterPic++);
689      if(rpcPic->getSlice(0)->isReferenced() == false)
690      {
691        break;
692      }
693    }
694  }
695  else
696  {
697    if ( getUseAdaptiveQP() )
698    {
699      TEncPic* pcEPic = new TEncPic;
700
701#if SVC_EXTENSION //Temporal solution, should be modified
702      if( m_layerId > 0 )
703      {
704        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
705        {
706          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
707          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
708          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
709          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
710
711          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
712
713          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
714          Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
715
716          if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase )
717          {
718            pcEPic->setEqualPictureSizeAndOffsetFlag( i, true );
719          }
720
721          if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
722#if CGS_3D_ASYMLUT
723            || m_cPPS.getCGSFlag() > 0
724#endif
725#if LAYER_CTB
726            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
727#endif
728            )
729          {
730            pcEPic->setSpatialEnhLayerFlag( i, true );
731
732            //only for scalable extension
733            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
734          }
735        }
736      }
737
738      pcEPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId);
739#else  //SVC_EXTENSION
740      pcEPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false);
741#endif //SVC_EXTENSION
742      rpcPic = pcEPic;
743    }
744    else
745    {
746      rpcPic = new TComPic;
747
748#if SVC_EXTENSION //Temporal solution, should be modified
749      if( m_layerId > 0 )
750      {
751        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
752        {
753          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
754          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
755          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
756          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
757
758          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
759
760          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
761          Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
762
763          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths
764            || !equalOffsets
765            || !zeroPhase
766#if CGS_3D_ASYMLUT
767            || m_cPPS.getCGSFlag() > 0
768#endif
769#if LAYER_CTB
770            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
771#endif
772            )
773          {
774            rpcPic->setSpatialEnhLayerFlag( i, true );
775
776            //only for scalable extension
777            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
778          }
779        }
780      }
781
782      rpcPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false, m_layerId );
783#else  //SVC_EXTENSION
784      rpcPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false );
785#endif //SVC_EXTENSION
786    }
787
788    m_cListPic.pushBack( rpcPic );
789  }
790  rpcPic->setReconMark (false);
791
792  m_iPOCLast++;
793  m_iNumPicRcvd++;
794
795  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
796  // mark it should be extended
797  rpcPic->getPicYuvRec()->setBorderExtension(false);
798}
799
800Void TEncTop::xInitVPS()
801{
802  // The SPS must have already been set up.
803  // set the VPS profile information.
804#if SVC_EXTENSION
805  m_cVPS.setVpsVuiPresentFlag( true );
806#else
807  *m_cVPS.getPTL() = *m_cSPS.getPTL();
808  m_cVPS.setMaxOpSets(1);
809#endif
810  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
811  m_cVPS.setNumHrdParameters( 0 );
812
813  m_cVPS.createHrdParamBuffer();
814  for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ )
815  {
816    m_cVPS.setHrdOpSetIdx( 0, i );
817    m_cVPS.setCprmsPresentFlag( false, i );
818    // Set up HrdParameters here.
819  }
820}
821
822
823Void TEncTop::xInitSPS()
824{
825#if SVC_EXTENSION
826  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
827  m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers);
828
829  if( !m_numDirectRefLayers && m_numAddLayerSets )
830  {
831    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
832  }
833  else
834  {
835    m_cSPS.setLayerId(m_layerId);
836  }
837#endif //SVC_EXTENSION
838
839  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
840  profileTierLevel.setLevelIdc(m_level);
841  profileTierLevel.setTierFlag(m_levelTier);
842  profileTierLevel.setProfileIdc(m_profile);
843  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
844  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
845  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
846  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
847  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
848  profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue);
849  profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue);
850  profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag);
851  profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag);
852
853  if ((m_profile == Profile::MAIN10) && (g_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (g_bitDepth[CHANNEL_TYPE_CHROMA] == 8))
854  {
855    /* The above constraint is equal to Profile::MAIN */
856    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
857  }
858  if (m_profile == Profile::MAIN)
859  {
860    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
861    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
862  }
863  /* XXX: should Main be marked as compatible with still picture? */
864  /* XXX: may be a good idea to refactor the above into a function
865   * that chooses the actual compatibility based upon options */
866
867  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
868  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
869  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
870  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
871  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
872  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
873  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
874
875  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
876  Int log2MinCUSize = 0;
877  while(minCUSize > 1)
878  {
879    minCUSize >>= 1;
880    log2MinCUSize++;
881  }
882
883  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
884  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth-getMaxCUDepthOffset(m_cSPS.getChromaFormatIdc(), m_cSPS.getQuadtreeTULog2MinSize()));
885#if SVC_EXTENSION
886  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
887#endif
888 
889  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
890  m_cSPS.setUsePCM        ( m_usePCM           );
891  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
892
893  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
894  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
895  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
896  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
897
898  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
899
900  m_cSPS.setTMVPFlagsPresent(false);
901
902  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
903 
904  m_cSPS.setUseAMP ( m_useAMP );
905
906  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
907  {
908#if SVC_EXTENSION
909    m_cSPS.setBitDepth    (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType))            );
910    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8)));
911#else
912    m_cSPS.setBitDepth    (ChannelType(channelType), g_bitDepth[channelType]            );
913    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (g_bitDepth[channelType] - 8)));
914#endif
915    m_cSPS.setPCMBitDepth (ChannelType(channelType), g_PCMBitDepth[channelType]         );
916  }
917
918  m_cSPS.setUseExtendedPrecision(m_useExtendedPrecision);
919  m_cSPS.setUseHighPrecisionPredictionWeighting(m_useHighPrecisionPredictionWeighting);
920
921  m_cSPS.setUseSAO( m_bUseSAO );
922  m_cSPS.setUseResidualRotation(m_useResidualRotation);
923  m_cSPS.setUseSingleSignificanceMapContext(m_useSingleSignificanceMapContext);
924  m_cSPS.setUseGolombRiceParameterAdaptation(m_useGolombRiceParameterAdaptation);
925  m_cSPS.setAlignCABACBeforeBypass(m_alignCABACBeforeBypass);
926
927  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
928  {
929    m_cSPS.setUseResidualDPCM(RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]);
930  }
931
932  m_cSPS.setMaxTLayers( m_maxTempLayer );
933  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
934
935  for ( Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
936  {
937#if SVC_EXTENSION
938    assert(i < MAX_TLAYER);
939#endif
940    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
941    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
942  }
943
944  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
945  m_cSPS.setDisableIntraReferenceSmoothing( m_disableIntraReferenceSmoothing );
946  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
947  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
948  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
949
950  if (m_cSPS.getVuiParametersPresentFlag())
951  {
952    TComVUI* pcVUI = m_cSPS.getVuiParameters();
953    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
954    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
955    pcVUI->setSarWidth(getSarWidth());
956    pcVUI->setSarHeight(getSarHeight());
957    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
958    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
959    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
960    pcVUI->setVideoFormat(getVideoFormat());
961    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
962    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
963    pcVUI->setColourPrimaries(getColourPrimaries());
964    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
965    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
966    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
967    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
968    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
969    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
970    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
971    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
972    pcVUI->setFieldSeqFlag(false);
973    pcVUI->setHrdParametersPresentFlag(false);
974    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
975    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
976    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
977    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
978    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
979    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
980    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
981    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
982    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
983    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
984  }
985  m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
986  assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS);
987  for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
988  {
989    m_cSPS.setLtRefPicPocLsbSps(k, 0);
990    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
991  }
992  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
993  {
994#if SVC_EXTENSION
995    const UInt picWidth = m_cVPS.getPicWidthInLumaSamples(&m_cSPS, m_layerId);
996    const UInt picHeight= m_cVPS.getPicWidthInLumaSamples(&m_cSPS, m_layerId);
997#else
998    const UInt picWidth = m_cSPS.getPicWidthInLumaSamples();
999    const UInt picHeight= m_cSPS.getPicWidthInLumaSamples();
1000#endif
1001
1002    const UInt frameWidthInCtus   = ( picWidth + g_uiMaxCUWidth -1 ) / g_uiMaxCUWidth;
1003    const UInt frameHeightInCtus  = ( picHeight + g_uiMaxCUHeight - 1 ) / g_uiMaxCUHeight;
1004    const UInt numCtusInFrame = frameWidthInCtus * frameHeightInCtus;
1005
1006    UInt maxCU = getSliceArgument();
1007    UInt numDU = ( getSliceMode() == FIXED_NUMBER_OF_CTU ) ? ( numCtusInFrame / maxCU ) : ( 0 );
1008    if( numCtusInFrame % maxCU != 0 || numDU == 0 )
1009    {
1010      numDU ++;
1011    }
1012    m_cSPS.getVuiParameters()->getHrdParameters()->setNumDU( numDU );
1013    m_cSPS.setHrdParameters( getFrameRate(), numDU, getTargetBitrate(), ( getIntraPeriod() > 0 ) );
1014  }
1015  if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
1016  {
1017    m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true );
1018  }
1019
1020}
1021
1022Void TEncTop::xInitPPS()
1023{
1024  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1025  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1026
1027  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1028  {
1029    bUseDQP = true;
1030  }
1031
1032  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
1033  {
1034    bUseDQP=false;
1035  }
1036
1037
1038  if ( m_RCEnableRateControl )
1039  {
1040    m_cPPS.setUseDQP(true);
1041    m_cPPS.setMaxCuDQPDepth( 0 );
1042  }
1043  else if(bUseDQP)
1044  {
1045    m_cPPS.setUseDQP(true);
1046    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1047  }
1048  else
1049  {
1050    m_cPPS.setUseDQP(false);
1051    m_cPPS.setMaxCuDQPDepth( 0 );
1052  }
1053
1054  if ( m_maxCUChromaQpAdjustmentDepth >= 0 )
1055  {
1056    m_cPPS.setMaxCuChromaQpAdjDepth(m_maxCUChromaQpAdjustmentDepth);
1057    m_cPPS.setChromaQpAdjTableAt(1, 6, 6);
1058    /* todo, insert table entries from command line (NB, 0 should not be touched) */
1059  }
1060  else
1061  {
1062    m_cPPS.setMaxCuChromaQpAdjDepth(0);
1063    m_cPPS.clearChromaQpAdjTable();
1064  }
1065
1066  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1067  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
1068
1069  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1070  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1071  m_cPPS.setUseWP( m_useWeightedPred );
1072  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1073  m_cPPS.setUseCrossComponentPrediction(m_useCrossComponentPrediction);
1074  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_LUMA,   m_saoOffsetBitShift[CHANNEL_TYPE_LUMA  ]);
1075  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA]);
1076  m_cPPS.setOutputFlagPresentFlag( false );
1077  m_cPPS.setSignHideFlag(getSignHideFlag());
1078  if ( getDeblockingFilterMetric() )
1079  {
1080    m_cPPS.setDeblockingFilterControlPresentFlag (true);
1081    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1082    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1083    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1084    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1085  }
1086  else
1087  {
1088    m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
1089
1090    if (m_cPPS.getDeblockingFilterControlPresentFlag())
1091    {
1092      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1093      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1094    }
1095  }
1096
1097  if (m_cPPS.getDeblockingFilterControlPresentFlag() && ! m_cPPS.getPicDisableDeblockingFilterFlag())
1098  {
1099    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1100    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
1101  }
1102  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1103  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1104  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1105
1106  Int histogram[MAX_NUM_REF + 1];
1107  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1108  {
1109    histogram[i]=0;
1110  }
1111  for( Int i = 0; i < getGOPSize(); i++)
1112  {
1113    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1114    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1115  }
1116
1117  Int maxHist=-1;
1118  Int bestPos=0;
1119  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1120  {
1121    if(histogram[i]>maxHist)
1122    {
1123      maxHist=histogram[i];
1124      bestPos=i;
1125    }
1126  }
1127  assert(bestPos <= 15);
1128  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1129  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1130  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1131  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1132  m_cPPS.setTransformSkipLog2MaxSize( m_transformSkipLog2MaxSize  );
1133
1134  if (m_sliceSegmentMode != NO_SLICES)
1135  {
1136    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1137  }
1138 
1139#if SVC_EXTENSION
1140  m_cPPS.setLayerId( m_layerId );
1141
1142  if( !m_numDirectRefLayers && m_numAddLayerSets )
1143  {
1144    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
1145  }
1146
1147  if( m_layerId > 0 )
1148  {
1149    m_cPPS.setListsModificationPresentFlag(true);
1150    m_cPPS.setExtensionFlag(true);
1151  }
1152  else
1153  {
1154    m_cPPS.setListsModificationPresentFlag(false);
1155    m_cPPS.setExtensionFlag(false);
1156  }
1157
1158  m_cPPS.setPPSId( m_iPPSIdCnt );
1159  m_cPPS.setSPSId( m_iSPSIdCnt );
1160
1161  if( m_crossLayerBLAFlag )
1162  {
1163    m_cPPS.setNumExtraSliceHeaderBits( 3 );
1164  }
1165
1166  m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets);
1167  for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++)
1168  {
1169    m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]);
1170    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
1171    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
1172    m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] );
1173    m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] );
1174    m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] );
1175    m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] );
1176    m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] );
1177    m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] );
1178    m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] );
1179  }
1180#if CGS_3D_ASYMLUT
1181  m_cPPS.setCGSFlag( m_nCGSFlag );
1182#endif
1183  m_cPPS.setPocResetInfoPresentFlag( true );
1184  m_cPPS.setExtensionFlag( true );
1185  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
1186#endif //SVC_EXTENSION
1187}
1188
1189//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1190Void TEncTop::xInitRPS(Bool isFieldCoding)
1191{
1192  TComReferencePictureSet*      rps;
1193
1194  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
1195  TComRPSList* rpsList = m_cSPS.getRPSList();
1196
1197  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
1198  {
1199    GOPEntry ge = getGOPEntry(i);
1200    rps = rpsList->getReferencePictureSet(i);
1201    rps->setNumberOfPictures(ge.m_numRefPics);
1202    rps->setNumRefIdc(ge.m_numRefIdc);
1203    Int numNeg = 0;
1204    Int numPos = 0;
1205    for( Int j = 0; j < ge.m_numRefPics; j++)
1206    {
1207      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1208      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1209      if(ge.m_referencePics[j]>0)
1210      {
1211        numPos++;
1212      }
1213      else
1214      {
1215        numNeg++;
1216      }
1217    }
1218    rps->setNumberOfNegativePictures(numNeg);
1219    rps->setNumberOfPositivePictures(numPos);
1220
1221    // handle inter RPS intialization from the config file.
1222#if AUTO_INTER_RPS
1223    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1224    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1225    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
1226
1227    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1228    {
1229      assert (RPSRef!=NULL);
1230      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1231      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1232
1233      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1234      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1235      Int count=0;
1236      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1237      {
1238        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1239        rps->setRefIdc(j, 0);
1240        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1241        {
1242          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1243          {
1244              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1245              count++;
1246              break;
1247          }
1248        }
1249      }
1250      if (count != rps->getNumberOfPictures())
1251      {
1252        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");
1253        rps->setInterRPSPrediction(0);
1254      }
1255    }
1256    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1257    {
1258      assert (RPSRef!=NULL);
1259      rps->setDeltaRPS(ge.m_deltaRPS);
1260      rps->setNumRefIdc(ge.m_numRefIdc);
1261      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1262      {
1263        rps->setRefIdc(j, ge.m_refIdc[j]);
1264      }
1265#if WRITE_BACK
1266      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1267      // computed from the RefIdc.  A warning is printed if they are not identical.
1268      numNeg = 0;
1269      numPos = 0;
1270      TComReferencePictureSet      RPSTemp;  // temporary variable
1271
1272      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1273      {
1274        if (ge.m_refIdc[j])
1275        {
1276          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1277          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1278          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1279          if (deltaPOC<0)
1280          {
1281            numNeg++;
1282          }
1283          else
1284          {
1285            numPos++;
1286          }
1287        }
1288      }
1289      if (numNeg != rps->getNumberOfNegativePictures())
1290      {
1291        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1292        rps->setNumberOfNegativePictures(numNeg);
1293        rps->setNumberOfPictures(numNeg+numPos);
1294      }
1295      if (numPos != rps->getNumberOfPositivePictures())
1296      {
1297        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1298        rps->setNumberOfPositivePictures(numPos);
1299        rps->setNumberOfPictures(numNeg+numPos);
1300      }
1301      RPSTemp.setNumberOfPictures(numNeg+numPos);
1302      RPSTemp.setNumberOfNegativePictures(numNeg);
1303      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1304      // check if Delta POC and Used are the same
1305      // print warning if they are not.
1306      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1307      {
1308        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1309        {
1310          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1311          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1312        }
1313        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1314        {
1315          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1316          rps->setUsed(j,RPSTemp.getUsed(j));
1317        }
1318      }
1319#endif
1320    }
1321#else
1322    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
1323    if (ge.m_interRPSPrediction)
1324    {
1325      rps->setDeltaRIdxMinus1(0);
1326      rps->setDeltaRPS(ge.m_deltaRPS);
1327      rps->setNumRefIdc(ge.m_numRefIdc);
1328      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1329      {
1330        rps->setRefIdc(j, ge.m_refIdc[j]);
1331      }
1332#if WRITE_BACK
1333      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1334      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
1335      numNeg = 0;
1336      numPos = 0;
1337      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
1338
1339      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1340      {
1341        if (ge.m_refIdc[j])
1342        {
1343          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1344          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
1345          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1346          if (deltaPOC<0)
1347          {
1348            numNeg++;
1349          }
1350          else
1351          {
1352            numPos++;
1353          }
1354        }
1355      }
1356      rps->setNumberOfNegativePictures(numNeg);
1357      rps->setNumberOfPositivePictures(numPos);
1358      rps->sortDeltaPOC();
1359#endif
1360    }
1361#endif //INTER_RPS_AUTO
1362  }
1363  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
1364  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1365  if (isFieldCoding)
1366  {
1367    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1368    rps->setNumberOfPictures(1);
1369    rps->setNumberOfNegativePictures(1);
1370    rps->setNumberOfPositivePictures(0);
1371    rps->setNumberOfLongtermPictures(0);
1372    rps->setDeltaPOC(0,-1);
1373    rps->setPOC(0,0);
1374    rps->setUsed(0,true);
1375    rps->setInterRPSPrediction(false);
1376    rps->setDeltaRIdxMinus1(0);
1377    rps->setDeltaRPS(0);
1378    rps->setNumRefIdc(0);
1379  }
1380}
1381
1382   // This is a function that
1383   // determines what Reference Picture Set to use
1384   // for a specific slice (with POC = POCCurr)
1385Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1386{
1387  slice->setRPSidx(GOPid);
1388
1389  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1390  {
1391    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1392    {
1393      Int POCIndex = POCCurr%m_uiIntraPeriod;
1394      if(POCIndex == 0)
1395      {
1396        POCIndex = m_uiIntraPeriod;
1397      }
1398      if(POCIndex == m_GOPList[extraNum].m_POC)
1399      {
1400        slice->setRPSidx(extraNum);
1401      }
1402    }
1403    else
1404    {
1405      if(POCCurr==m_GOPList[extraNum].m_POC)
1406      {
1407        slice->setRPSidx(extraNum);
1408      }
1409    }
1410  }
1411
1412  if(POCCurr == 1 && slice->getPic()->isField())
1413  {
1414    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1415  }
1416
1417  TComReferencePictureSet *rps=slice->getLocalRPS();
1418  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1419  slice->setRPS(rps);
1420  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1421}
1422
1423Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
1424{
1425  Int rpsIdx = GOPid;
1426
1427  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1428  {
1429    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1430    {
1431      Int POCIndex = POCCurr%m_uiIntraPeriod;
1432      if(POCIndex == 0)
1433      {
1434        POCIndex = m_uiIntraPeriod;
1435      }
1436      if(POCIndex == m_GOPList[extraNum].m_POC)
1437      {
1438        rpsIdx = extraNum;
1439      }
1440    }
1441    else
1442    {
1443      if(POCCurr==m_GOPList[extraNum].m_POC)
1444      {
1445        rpsIdx = extraNum;
1446      }
1447    }
1448  }
1449
1450  return rpsIdx;
1451}
1452
1453Void  TEncTop::xInitPPSforTiles()
1454{
1455  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1456  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1457  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1458  if( !m_tileUniformSpacingFlag )
1459  {
1460    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1461    m_cPPS.setTileRowHeight( m_tileRowHeight );
1462  }
1463  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1464
1465  // # substreams is "per tile" when tiles are independent.
1466}
1467
1468Void  TEncCfg::xCheckGSParameters()
1469{
1470  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1471  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1472  UInt  uiCummulativeColumnWidth = 0;
1473  UInt  uiCummulativeRowHeight = 0;
1474
1475  //check the column relative parameters
1476  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1477  {
1478    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1479    exit( EXIT_FAILURE );
1480  }
1481
1482  if( m_iNumColumnsMinus1 >= iWidthInCU )
1483  {
1484    printf( "The current picture can not have so many columns.\n" );
1485    exit( EXIT_FAILURE );
1486  }
1487
1488  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1489  {
1490    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1491    {
1492      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1493    }
1494
1495    if( uiCummulativeColumnWidth >= iWidthInCU )
1496    {
1497      printf( "The width of the column is too large.\n" );
1498      exit( EXIT_FAILURE );
1499    }
1500  }
1501
1502  //check the row relative parameters
1503  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1504  {
1505    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1506    exit( EXIT_FAILURE );
1507  }
1508
1509  if( m_iNumRowsMinus1 >= iHeightInCU )
1510  {
1511    printf( "The current picture can not have so many rows.\n" );
1512    exit( EXIT_FAILURE );
1513  }
1514
1515  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1516  {
1517    for(Int i=0; i<m_iNumRowsMinus1; i++)
1518      uiCummulativeRowHeight += m_tileRowHeight[i];
1519
1520    if( uiCummulativeRowHeight >= iHeightInCU )
1521    {
1522      printf( "The height of the row is too large.\n" );
1523      exit( EXIT_FAILURE );
1524    }
1525  }
1526}
1527
1528#if SVC_EXTENSION
1529TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx )
1530{
1531  if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 )
1532  {
1533    return (TEncTop *)getLayerEnc( 0 );
1534  }
1535
1536  return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) );
1537}
1538
1539Void TEncTop::xInitILRP()
1540{
1541  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) );
1542  Int bitDepthY,bitDepthC,picWidth,picHeight;
1543
1544  bitDepthY   = repFormat->getBitDepthVpsLuma();
1545  bitDepthC   = repFormat->getBitDepthVpsChroma();
1546  picWidth    = repFormat->getPicWidthVpsInLumaSamples();
1547  picHeight   = repFormat->getPicHeightVpsInLumaSamples();
1548 
1549  if( m_layerId > 0 )
1550  {
1551    g_bitDepth[CHANNEL_TYPE_LUMA]   = bitDepthY;
1552    g_bitDepth[CHANNEL_TYPE_CHROMA] = bitDepthC;
1553    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1554    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1555    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1556    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1557
1558    if (m_cIlpPic[0] == NULL)
1559    {
1560      for (Int j=0; j < m_numDirectRefLayers; j++)
1561      {
1562        m_cIlpPic[j] = new TComPic;
1563        m_cIlpPic[j]->create(m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true, m_layerId);
1564        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
1565        {
1566          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
1567        }
1568      }
1569    }
1570
1571    if( m_cVPS.getNumRefLayers( m_layerId ) == 0 )
1572    {
1573      UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId );
1574      RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx));
1575     
1576      if( m_cPPS.getLayerId() == 0 && 
1577          m_cSPS.getLayerId() == 0 &&
1578          repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() &&
1579          repFmt->getSeparateColourPlaneVpsFlag() == 0 &&
1580          repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() &&
1581          repFmt->getPicWidthVpsInLumaSamples()  == m_cSPS.getPicWidthInLumaSamples() &&
1582          repFmt->getBitDepthVpsLuma()   == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) &&
1583          repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) &&
1584          repFmt->getConformanceWindowVps().getWindowLeftOffset()   == m_cSPS.getConformanceWindow().getWindowLeftOffset() &&
1585          repFmt->getConformanceWindowVps().getWindowRightOffset()  == m_cSPS.getConformanceWindow().getWindowRightOffset() &&
1586          repFmt->getConformanceWindowVps().getWindowTopOffset()    == m_cSPS.getConformanceWindow().getWindowTopOffset() &&
1587          repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() )
1588      {
1589        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1);
1590      }
1591      else
1592      {
1593        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0);
1594      }
1595    }
1596  }
1597}
1598
1599Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
1600{
1601  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1602  {
1603    if (layerId == m_refLocationOffsetLayerId[i])
1604    {
1605      return m_scaledRefLayerWindow[i];
1606    }
1607  }
1608
1609  return Window();
1610}
1611
1612Window TEncTop::getRefLayerWindowForLayer(Int layerId)
1613{
1614  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1615  {
1616    if (layerId == m_refLayerId[i])
1617    {
1618      return m_refLayerWindow[i];
1619    }
1620  }
1621
1622  return Window();
1623}
1624#endif //SVC_EXTENSION
1625//! \}
Note: See TracBrowser for help on using the repository browser.