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

Last change on this file since 1263 was 1260, checked in by seregin, 9 years ago

port rev 4257

  • Property svn:eol-style set to native
File size: 54.8 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, 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, &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 \param   pcPicYuvTrueOrg     
398 \param   snrCSC
399 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
400 \retval  accessUnitsOut      list of output access units
401 \retval  iNumEncoded         number of encoded pictures
402 */
403#if SVC_EXTENSION
404Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
405{
406  // compress GOP
407#if !RC_SHVC_HARMONIZATION
408  if ( m_RCEnableRateControl )
409  {
410    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
411  }
412#endif
413
414  // compress GOP
415  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
416
417#if !RC_SHVC_HARMONIZATION
418  if ( m_RCEnableRateControl )
419  {
420    m_cRateCtrl.destroyRCGOP();
421  }
422#endif
423 
424  m_uiNumAllPicCoded ++;
425}
426
427Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg )
428{
429  if (pcPicYuvOrg != NULL)
430  {
431    // get original YUV
432    TComPic* pcPicCurr = NULL;
433    xGetNewPicBuffer( pcPicCurr );
434    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
435    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
436
437    // compute image characteristics
438    if ( getUseAdaptiveQP() )
439    {
440      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
441    }
442  }
443}
444#else
445Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
446{
447  if (pcPicYuvOrg != NULL)
448  {
449    // get original YUV
450    TComPic* pcPicCurr = NULL;
451
452    xGetNewPicBuffer( pcPicCurr );
453    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
454    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
455
456    // compute image characteristics
457    if ( getUseAdaptiveQP() )
458    {
459      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
460    }
461  }
462
463  if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0)))
464  {
465    iNumEncoded = 0;
466    return;
467  }
468
469  if ( m_RCEnableRateControl )
470  {
471    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
472  }
473
474  // compress GOP
475  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
476
477  if ( m_RCEnableRateControl )
478  {
479    m_cRateCtrl.destroyRCGOP();
480  }
481
482  iNumEncoded         = m_iNumPicRcvd;
483  m_iNumPicRcvd       = 0;
484  m_uiNumAllPicCoded += iNumEncoded;
485}
486#endif
487
488/**------------------------------------------------
489 Separate interlaced frame into two fields
490 -------------------------------------------------**/
491Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
492{
493  if (!isTop)
494  {
495    org += stride;
496  }
497  for (Int y = 0; y < height>>1; y++)
498  {
499    for (Int x = 0; x < width; x++)
500    {
501      dstField[x] = org[x];
502    }
503
504    dstField += stride;
505    org += stride*2;
506  }
507
508}
509
510#if SVC_EXTENSION
511Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff )
512{
513  for (Int fieldNum=0; fieldNum<2; fieldNum++)
514  {
515    if (pcPicYuvOrg)
516    {
517      /* -- field initialization -- */
518      const Bool isTopField=isTff==(fieldNum==0);
519
520      TComPic *pcField;
521      xGetNewPicBuffer( pcField );
522      pcField->setReconMark (false);                     // where is this normally?
523           
524      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
525      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
526
527      pcField->setTopField(isTopField);                  // interlaced requirement
528
529      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
530      {
531        const ComponentID component = ComponentID(componentIndex);
532        const UInt stride = pcPicYuvOrg->getStride(component);
533
534        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
535                       pcField->getPicYuvOrg()->getAddr(component),
536                       pcPicYuvOrg->getStride(component),
537                       pcPicYuvOrg->getWidth(component),
538                       pcPicYuvOrg->getHeight(component),
539                       isTopField);
540
541        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
542                       pcField->getPicYuvTrueOrg()->getAddr(component),
543                       pcPicYuvTrueOrg->getStride(component),
544                       pcPicYuvTrueOrg->getWidth(component),
545                       pcPicYuvTrueOrg->getHeight(component),
546                       isTopField);
547      }
548
549      // compute image characteristics
550      if ( getUseAdaptiveQP() )
551      {
552        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
553      }
554    }
555  }
556}
557
558Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
559{
560  for (Int fieldNum=0; fieldNum<2; fieldNum++)
561  {
562    if (pcPicYuvOrg)
563    {
564      if (fieldNum==1)                                   // where is this normally?
565      {
566        TComPicYuv* rpcPicYuvRec;
567
568        // org. buffer
569        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.
570        {
571          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
572        }
573        else
574        {
575          rpcPicYuvRec = new TComPicYuv;
576          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
577        }
578        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
579      }
580    }
581
582    // compress GOP
583    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
584  }
585
586  m_uiNumAllPicCoded ++;
587}
588#else
589Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
590{
591  iNumEncoded = 0;
592
593  for (Int fieldNum=0; fieldNum<2; fieldNum++)
594  {
595    if (pcPicYuvOrg)
596    {
597
598      /* -- field initialization -- */
599      const Bool isTopField=isTff==(fieldNum==0);
600
601      TComPic *pcField;
602      xGetNewPicBuffer( pcField );
603      pcField->setReconMark (false);                     // where is this normally?
604
605      if (fieldNum==1)                                   // where is this normally?
606      {
607        TComPicYuv* rpcPicYuvRec;
608
609        // org. buffer
610        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.
611        {
612          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
613        }
614        else
615        {
616          rpcPicYuvRec = new TComPicYuv;
617          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
618        }
619        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
620      }
621
622      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
623      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
624
625      pcField->setTopField(isTopField);                  // interlaced requirement
626
627      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
628      {
629        const ComponentID component = ComponentID(componentIndex);
630        const UInt stride = pcPicYuvOrg->getStride(component);
631
632        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
633                       pcField->getPicYuvOrg()->getAddr(component),
634                       pcPicYuvOrg->getStride(component),
635                       pcPicYuvOrg->getWidth(component),
636                       pcPicYuvOrg->getHeight(component),
637                       isTopField);
638
639        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
640                       pcField->getPicYuvTrueOrg()->getAddr(component),
641                       pcPicYuvTrueOrg->getStride(component),
642                       pcPicYuvTrueOrg->getWidth(component),
643                       pcPicYuvTrueOrg->getHeight(component),
644                       isTopField);
645      }
646
647      // compute image characteristics
648      if ( getUseAdaptiveQP() )
649      {
650        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
651      }
652    }
653
654    if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
655    {
656      // compress GOP
657      m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
658
659      iNumEncoded += m_iNumPicRcvd;
660      m_uiNumAllPicCoded += m_iNumPicRcvd;
661      m_iNumPicRcvd = 0;
662    }
663  }
664}
665#endif
666
667// ====================================================================================================================
668// Protected member functions
669// ====================================================================================================================
670
671/**
672 - Application has picture buffer list with size of GOP + 1
673 - Picture buffer list acts like as ring buffer
674 - End of the list has the latest picture
675 .
676 \retval rpcPic obtained picture buffer
677 */
678Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
679{
680  // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
681
682  TComSlice::sortPicList(m_cListPic);
683
684
685  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
686  {
687    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
688    Int iSize = Int( m_cListPic.size() );
689    for ( Int i = 0; i < iSize; i++ )
690    {
691      rpcPic = *(iterPic++);
692      if(rpcPic->getSlice(0)->isReferenced() == false)
693      {
694        break;
695      }
696    }
697  }
698  else
699  {
700    if ( getUseAdaptiveQP() )
701    {
702      TEncPic* pcEPic = new TEncPic;
703
704#if SVC_EXTENSION //Temporal solution, should be modified
705      if( m_layerId > 0 )
706      {
707        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
708        {
709          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
710          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
711          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
712          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
713
714          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
715
716          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
717          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] );
718
719          if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase )
720          {
721            pcEPic->setEqualPictureSizeAndOffsetFlag( i, true );
722          }
723
724          if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
725#if CGS_3D_ASYMLUT
726            || m_cPPS.getCGSFlag() > 0
727#endif
728#if LAYER_CTB
729            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
730#endif
731            )
732          {
733            pcEPic->setSpatialEnhLayerFlag( i, true );
734
735            //only for scalable extension
736            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
737          }
738        }
739      }
740
741      pcEPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId);
742#else  //SVC_EXTENSION
743      pcEPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false);
744#endif //SVC_EXTENSION
745      rpcPic = pcEPic;
746    }
747    else
748    {
749      rpcPic = new TComPic;
750
751#if SVC_EXTENSION //Temporal solution, should be modified
752      if( m_layerId > 0 )
753      {
754        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
755        {
756          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
757          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
758          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
759          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
760
761          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
762
763          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
764          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] );
765
766          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths
767            || !equalOffsets
768            || !zeroPhase
769#if CGS_3D_ASYMLUT
770            || m_cPPS.getCGSFlag() > 0
771#endif
772#if LAYER_CTB
773            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
774#endif
775            )
776          {
777            rpcPic->setSpatialEnhLayerFlag( i, true );
778
779            //only for scalable extension
780            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
781          }
782        }
783      }
784
785      rpcPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false, m_layerId );
786#else  //SVC_EXTENSION
787      rpcPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false );
788#endif //SVC_EXTENSION
789    }
790
791    m_cListPic.pushBack( rpcPic );
792  }
793  rpcPic->setReconMark (false);
794
795  m_iPOCLast++;
796  m_iNumPicRcvd++;
797
798  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
799  // mark it should be extended
800  rpcPic->getPicYuvRec()->setBorderExtension(false);
801}
802
803Void TEncTop::xInitVPS()
804{
805  // The SPS must have already been set up.
806  // set the VPS profile information.
807#if SVC_EXTENSION
808  m_cVPS.setVpsVuiPresentFlag( true );
809#else
810  *m_cVPS.getPTL() = *m_cSPS.getPTL();
811  m_cVPS.setMaxOpSets(1);
812#endif
813  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
814  m_cVPS.setNumHrdParameters( 0 );
815
816  m_cVPS.createHrdParamBuffer();
817  for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ )
818  {
819    m_cVPS.setHrdOpSetIdx( 0, i );
820    m_cVPS.setCprmsPresentFlag( false, i );
821    // Set up HrdParameters here.
822  }
823}
824
825Void TEncTop::xInitSPS()
826{
827#if SVC_EXTENSION
828  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
829  m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers);
830
831  if( !m_numDirectRefLayers && m_numAddLayerSets )
832  {
833    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
834  }
835  else
836  {
837    m_cSPS.setLayerId(m_layerId);
838  }
839#endif //SVC_EXTENSION
840
841  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
842  profileTierLevel.setLevelIdc(m_level);
843  profileTierLevel.setTierFlag(m_levelTier);
844  profileTierLevel.setProfileIdc(m_profile);
845  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
846  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
847  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
848  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
849  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
850  profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue);
851  profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue);
852  profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag);
853  profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag);
854
855  if ((m_profile == Profile::MAIN10) && (g_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (g_bitDepth[CHANNEL_TYPE_CHROMA] == 8))
856  {
857    /* The above constraint is equal to Profile::MAIN */
858    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
859  }
860  if (m_profile == Profile::MAIN)
861  {
862    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
863    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
864  }
865  /* XXX: should Main be marked as compatible with still picture? */
866  /* XXX: may be a good idea to refactor the above into a function
867   * that chooses the actual compatibility based upon options */
868
869  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
870  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
871  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
872  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
873  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
874  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
875  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
876
877  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
878  Int log2MinCUSize = 0;
879  while(minCUSize > 1)
880  {
881    minCUSize >>= 1;
882    log2MinCUSize++;
883  }
884
885  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
886  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth-getMaxCUDepthOffset(m_cSPS.getChromaFormatIdc(), m_cSPS.getQuadtreeTULog2MinSize()));
887#if SVC_EXTENSION
888  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
889#endif
890 
891  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
892  m_cSPS.setUsePCM        ( m_usePCM           );
893  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
894
895  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
896  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
897  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
898  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
899
900  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
901
902  m_cSPS.setTMVPFlagsPresent(false);
903
904  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
905 
906  m_cSPS.setUseAMP ( m_useAMP );
907
908  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
909  {
910#if SVC_EXTENSION
911    m_cSPS.setBitDepth    (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType))            );
912    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8)));
913#else
914    m_cSPS.setBitDepth    (ChannelType(channelType), g_bitDepth[channelType]            );
915    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (g_bitDepth[channelType] - 8)));
916#endif
917    m_cSPS.setPCMBitDepth (ChannelType(channelType), g_PCMBitDepth[channelType]         );
918  }
919
920  m_cSPS.setUseExtendedPrecision(m_useExtendedPrecision);
921  m_cSPS.setUseHighPrecisionPredictionWeighting(m_useHighPrecisionPredictionWeighting);
922
923  m_cSPS.setUseSAO( m_bUseSAO );
924  m_cSPS.setUseResidualRotation(m_useResidualRotation);
925  m_cSPS.setUseSingleSignificanceMapContext(m_useSingleSignificanceMapContext);
926  m_cSPS.setUseGolombRiceParameterAdaptation(m_useGolombRiceParameterAdaptation);
927  m_cSPS.setAlignCABACBeforeBypass(m_alignCABACBeforeBypass);
928
929  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
930  {
931    m_cSPS.setUseResidualDPCM(RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]);
932  }
933
934  m_cSPS.setMaxTLayers( m_maxTempLayer );
935  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
936
937  for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
938  {
939#if SVC_EXTENSION
940    assert(i < MAX_TLAYER);
941#endif
942    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
943    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
944  }
945
946  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
947  m_cSPS.setDisableIntraReferenceSmoothing( m_disableIntraReferenceSmoothing );
948  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
949  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
950  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
951
952  if (m_cSPS.getVuiParametersPresentFlag())
953  {
954    TComVUI* pcVUI = m_cSPS.getVuiParameters();
955    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
956    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
957    pcVUI->setSarWidth(getSarWidth());
958    pcVUI->setSarHeight(getSarHeight());
959    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
960    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
961    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
962    pcVUI->setVideoFormat(getVideoFormat());
963    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
964    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
965    pcVUI->setColourPrimaries(getColourPrimaries());
966    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
967    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
968    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
969    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
970    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
971    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
972    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
973    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
974    pcVUI->setFieldSeqFlag(false);
975    pcVUI->setHrdParametersPresentFlag(false);
976    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
977    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
978    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
979    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
980    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
981    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
982    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
983    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
984    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
985    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
986  }
987  m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
988  assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS);
989  for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
990  {
991    m_cSPS.setLtRefPicPocLsbSps(k, 0);
992    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
993  }
994  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
995  {
996#if SVC_EXTENSION
997    const UInt picWidth = m_cVPS.getPicWidthInLumaSamples(&m_cSPS, m_layerId);
998    const UInt picHeight= m_cVPS.getPicWidthInLumaSamples(&m_cSPS, m_layerId);
999#else
1000    const UInt picWidth = m_cSPS.getPicWidthInLumaSamples();
1001    const UInt picHeight= m_cSPS.getPicWidthInLumaSamples();
1002#endif
1003
1004    const UInt frameWidthInCtus   = ( picWidth + g_uiMaxCUWidth -1 ) / g_uiMaxCUWidth;
1005    const UInt frameHeightInCtus  = ( picHeight + g_uiMaxCUHeight - 1 ) / g_uiMaxCUHeight;
1006    const UInt numCtusInFrame = frameWidthInCtus * frameHeightInCtus;
1007
1008    UInt maxCU = getSliceArgument();
1009    UInt numDU = ( getSliceMode() == FIXED_NUMBER_OF_CTU ) ? ( numCtusInFrame / maxCU ) : ( 0 );
1010    if( numCtusInFrame % maxCU != 0 || numDU == 0 )
1011    {
1012      numDU ++;
1013    }
1014    m_cSPS.getVuiParameters()->getHrdParameters()->setNumDU( numDU );
1015    m_cSPS.setHrdParameters( getFrameRate(), numDU, getTargetBitrate(), ( getIntraPeriod() > 0 ) );
1016  }
1017  if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
1018  {
1019    m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true );
1020  }
1021
1022}
1023
1024Void TEncTop::xInitPPS()
1025{
1026  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1027  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1028
1029  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1030  {
1031    bUseDQP = true;
1032  }
1033
1034  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
1035  {
1036    bUseDQP=false;
1037  }
1038
1039
1040  if ( m_RCEnableRateControl )
1041  {
1042    m_cPPS.setUseDQP(true);
1043    m_cPPS.setMaxCuDQPDepth( 0 );
1044  }
1045  else if(bUseDQP)
1046  {
1047    m_cPPS.setUseDQP(true);
1048    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1049  }
1050  else
1051  {
1052    m_cPPS.setUseDQP(false);
1053    m_cPPS.setMaxCuDQPDepth( 0 );
1054  }
1055
1056  if ( m_maxCUChromaQpAdjustmentDepth >= 0 )
1057  {
1058    m_cPPS.setMaxCuChromaQpAdjDepth(m_maxCUChromaQpAdjustmentDepth);
1059    m_cPPS.setChromaQpAdjTableAt(1, 6, 6);
1060    /* todo, insert table entries from command line (NB, 0 should not be touched) */
1061  }
1062  else
1063  {
1064    m_cPPS.setMaxCuChromaQpAdjDepth(0);
1065    m_cPPS.clearChromaQpAdjTable();
1066  }
1067
1068  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1069  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
1070
1071  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1072  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1073  m_cPPS.setUseWP( m_useWeightedPred );
1074  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1075  m_cPPS.setUseCrossComponentPrediction(m_useCrossComponentPrediction);
1076  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_LUMA,   m_saoOffsetBitShift[CHANNEL_TYPE_LUMA  ]);
1077  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA]);
1078  m_cPPS.setOutputFlagPresentFlag( false );
1079  m_cPPS.setSignHideFlag(getSignHideFlag());
1080  if ( getDeblockingFilterMetric() )
1081  {
1082    m_cPPS.setDeblockingFilterControlPresentFlag (true);
1083    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1084    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1085    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1086    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1087  }
1088  else
1089  {
1090    m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
1091
1092    if (m_cPPS.getDeblockingFilterControlPresentFlag())
1093    {
1094      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1095      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1096    }
1097  }
1098
1099  if (m_cPPS.getDeblockingFilterControlPresentFlag() && ! m_cPPS.getPicDisableDeblockingFilterFlag())
1100  {
1101    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1102    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
1103  }
1104  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1105  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1106  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1107
1108
1109  Int histogram[MAX_NUM_REF + 1];
1110  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1111  {
1112    histogram[i]=0;
1113  }
1114  for( Int i = 0; i < getGOPSize(); i++)
1115  {
1116    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1117    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1118  }
1119
1120  Int maxHist=-1;
1121  Int bestPos=0;
1122  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1123  {
1124    if(histogram[i]>maxHist)
1125    {
1126      maxHist=histogram[i];
1127      bestPos=i;
1128    }
1129  }
1130  assert(bestPos <= 15);
1131  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1132  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1133  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1134  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1135  m_cPPS.setTransformSkipLog2MaxSize( m_transformSkipLog2MaxSize  );
1136
1137  if (m_sliceSegmentMode != NO_SLICES)
1138  {
1139    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1140  }
1141 
1142#if SVC_EXTENSION
1143  m_cPPS.setLayerId( m_layerId );
1144
1145  if( !m_numDirectRefLayers && m_numAddLayerSets )
1146  {
1147    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
1148  }
1149
1150  if( m_layerId > 0 )
1151  {
1152    m_cPPS.setListsModificationPresentFlag(true);
1153    m_cPPS.setExtensionFlag(true);
1154  }
1155  else
1156  {
1157    m_cPPS.setListsModificationPresentFlag(false);
1158    m_cPPS.setExtensionFlag(false);
1159  }
1160
1161  m_cPPS.setPPSId( m_iPPSIdCnt );
1162  m_cPPS.setSPSId( m_iSPSIdCnt );
1163
1164  if( m_crossLayerBLAFlag )
1165  {
1166    m_cPPS.setNumExtraSliceHeaderBits( 3 );
1167  }
1168
1169  m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets);
1170  for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++)
1171  {
1172    m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]);
1173    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
1174    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
1175    m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] );
1176    m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] );
1177    m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] );
1178    m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] );
1179    m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] );
1180    m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] );
1181    m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] );
1182  }
1183#if CGS_3D_ASYMLUT
1184  m_cPPS.setCGSFlag( m_nCGSFlag );
1185#endif
1186  m_cPPS.setPocResetInfoPresentFlag( true );
1187  m_cPPS.setExtensionFlag( true );
1188  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
1189#endif //SVC_EXTENSION
1190}
1191
1192//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1193Void TEncTop::xInitRPS(Bool isFieldCoding)
1194{
1195  TComReferencePictureSet*      rps;
1196
1197  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
1198  TComRPSList* rpsList = m_cSPS.getRPSList();
1199
1200  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
1201  {
1202    GOPEntry ge = getGOPEntry(i);
1203    rps = rpsList->getReferencePictureSet(i);
1204    rps->setNumberOfPictures(ge.m_numRefPics);
1205    rps->setNumRefIdc(ge.m_numRefIdc);
1206    Int numNeg = 0;
1207    Int numPos = 0;
1208    for( Int j = 0; j < ge.m_numRefPics; j++)
1209    {
1210      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1211      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1212      if(ge.m_referencePics[j]>0)
1213      {
1214        numPos++;
1215      }
1216      else
1217      {
1218        numNeg++;
1219      }
1220    }
1221    rps->setNumberOfNegativePictures(numNeg);
1222    rps->setNumberOfPositivePictures(numPos);
1223
1224    // handle inter RPS intialization from the config file.
1225    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1226    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1227    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
1228
1229    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1230    {
1231      assert (RPSRef!=NULL);
1232      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1233      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1234
1235      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1236      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1237      Int count=0;
1238      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1239      {
1240        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1241        rps->setRefIdc(j, 0);
1242        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1243        {
1244          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1245          {
1246              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1247              count++;
1248              break;
1249          }
1250        }
1251      }
1252      if (count != rps->getNumberOfPictures())
1253      {
1254        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");
1255        rps->setInterRPSPrediction(0);
1256      }
1257    }
1258    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1259    {
1260      assert (RPSRef!=NULL);
1261      rps->setDeltaRPS(ge.m_deltaRPS);
1262      rps->setNumRefIdc(ge.m_numRefIdc);
1263      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1264      {
1265        rps->setRefIdc(j, ge.m_refIdc[j]);
1266      }
1267#if WRITE_BACK
1268      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
1269      // computed from the RefIdc.  A warning is printed if they are not identical.
1270      numNeg = 0;
1271      numPos = 0;
1272      TComReferencePictureSet      RPSTemp;  // temporary variable
1273
1274      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1275      {
1276        if (ge.m_refIdc[j])
1277        {
1278          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1279          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1280          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1281          if (deltaPOC<0)
1282          {
1283            numNeg++;
1284          }
1285          else
1286          {
1287            numPos++;
1288          }
1289        }
1290      }
1291      if (numNeg != rps->getNumberOfNegativePictures())
1292      {
1293        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1294        rps->setNumberOfNegativePictures(numNeg);
1295        rps->setNumberOfPictures(numNeg+numPos);
1296      }
1297      if (numPos != rps->getNumberOfPositivePictures())
1298      {
1299        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1300        rps->setNumberOfPositivePictures(numPos);
1301        rps->setNumberOfPictures(numNeg+numPos);
1302      }
1303      RPSTemp.setNumberOfPictures(numNeg+numPos);
1304      RPSTemp.setNumberOfNegativePictures(numNeg);
1305      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1306      // check if Delta POC and Used are the same
1307      // print warning if they are not.
1308      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1309      {
1310        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1311        {
1312          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1313          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1314        }
1315        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1316        {
1317          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1318          rps->setUsed(j,RPSTemp.getUsed(j));
1319        }
1320      }
1321#endif
1322    }
1323  }
1324  //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.
1325  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1326  if (isFieldCoding)
1327  {
1328    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1329    rps->setNumberOfPictures(1);
1330    rps->setNumberOfNegativePictures(1);
1331    rps->setNumberOfPositivePictures(0);
1332    rps->setNumberOfLongtermPictures(0);
1333    rps->setDeltaPOC(0,-1);
1334    rps->setPOC(0,0);
1335    rps->setUsed(0,true);
1336    rps->setInterRPSPrediction(false);
1337    rps->setDeltaRIdxMinus1(0);
1338    rps->setDeltaRPS(0);
1339    rps->setNumRefIdc(0);
1340  }
1341}
1342
1343   // This is a function that
1344   // determines what Reference Picture Set to use
1345   // for a specific slice (with POC = POCCurr)
1346Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1347{
1348  slice->setRPSidx(GOPid);
1349
1350  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1351  {
1352    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1353    {
1354      Int POCIndex = POCCurr%m_uiIntraPeriod;
1355      if(POCIndex == 0)
1356      {
1357        POCIndex = m_uiIntraPeriod;
1358      }
1359      if(POCIndex == m_GOPList[extraNum].m_POC)
1360      {
1361        slice->setRPSidx(extraNum);
1362      }
1363    }
1364    else
1365    {
1366      if(POCCurr==m_GOPList[extraNum].m_POC)
1367      {
1368        slice->setRPSidx(extraNum);
1369      }
1370    }
1371  }
1372
1373  if(POCCurr == 1 && slice->getPic()->isField())
1374  {
1375    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1376  }
1377
1378  TComReferencePictureSet *rps=slice->getLocalRPS();
1379  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1380  slice->setRPS(rps);
1381  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1382}
1383
1384Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
1385{
1386  Int rpsIdx = GOPid;
1387
1388  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1389  {
1390    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1391    {
1392      Int POCIndex = POCCurr%m_uiIntraPeriod;
1393      if(POCIndex == 0)
1394      {
1395        POCIndex = m_uiIntraPeriod;
1396      }
1397      if(POCIndex == m_GOPList[extraNum].m_POC)
1398      {
1399        rpsIdx = extraNum;
1400      }
1401    }
1402    else
1403    {
1404      if(POCCurr==m_GOPList[extraNum].m_POC)
1405      {
1406        rpsIdx = extraNum;
1407      }
1408    }
1409  }
1410
1411  return rpsIdx;
1412}
1413
1414Void  TEncTop::xInitPPSforTiles()
1415{
1416  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1417  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1418  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1419  if( !m_tileUniformSpacingFlag )
1420  {
1421    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1422    m_cPPS.setTileRowHeight( m_tileRowHeight );
1423  }
1424  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1425
1426  // # substreams is "per tile" when tiles are independent.
1427}
1428
1429Void  TEncCfg::xCheckGSParameters()
1430{
1431  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1432  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1433  UInt  uiCummulativeColumnWidth = 0;
1434  UInt  uiCummulativeRowHeight = 0;
1435
1436  //check the column relative parameters
1437  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1438  {
1439    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1440    exit( EXIT_FAILURE );
1441  }
1442
1443  if( m_iNumColumnsMinus1 >= iWidthInCU )
1444  {
1445    printf( "The current picture can not have so many columns.\n" );
1446    exit( EXIT_FAILURE );
1447  }
1448
1449  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1450  {
1451    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1452    {
1453      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1454    }
1455
1456    if( uiCummulativeColumnWidth >= iWidthInCU )
1457    {
1458      printf( "The width of the column is too large.\n" );
1459      exit( EXIT_FAILURE );
1460    }
1461  }
1462
1463  //check the row relative parameters
1464  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1465  {
1466    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1467    exit( EXIT_FAILURE );
1468  }
1469
1470  if( m_iNumRowsMinus1 >= iHeightInCU )
1471  {
1472    printf( "The current picture can not have so many rows.\n" );
1473    exit( EXIT_FAILURE );
1474  }
1475
1476  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1477  {
1478    for(Int i=0; i<m_iNumRowsMinus1; i++)
1479    {
1480      uiCummulativeRowHeight += m_tileRowHeight[i];
1481    }
1482
1483    if( uiCummulativeRowHeight >= iHeightInCU )
1484    {
1485      printf( "The height of the row is too large.\n" );
1486      exit( EXIT_FAILURE );
1487    }
1488  }
1489}
1490
1491#if SVC_EXTENSION
1492TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx )
1493{
1494  if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 )
1495  {
1496    return (TEncTop *)getLayerEnc( 0 );
1497  }
1498
1499  return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) );
1500}
1501
1502Void TEncTop::xInitILRP()
1503{
1504  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) );
1505  Int bitDepthY,bitDepthC,picWidth,picHeight;
1506
1507  bitDepthY   = repFormat->getBitDepthVpsLuma();
1508  bitDepthC   = repFormat->getBitDepthVpsChroma();
1509  picWidth    = repFormat->getPicWidthVpsInLumaSamples();
1510  picHeight   = repFormat->getPicHeightVpsInLumaSamples();
1511 
1512  if( m_layerId > 0 )
1513  {
1514    g_bitDepth[CHANNEL_TYPE_LUMA]   = bitDepthY;
1515    g_bitDepth[CHANNEL_TYPE_CHROMA] = bitDepthC;
1516    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1517    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1518    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1519    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1520
1521    if (m_cIlpPic[0] == NULL)
1522    {
1523      for (Int j=0; j < m_numDirectRefLayers; j++)
1524      {
1525        m_cIlpPic[j] = new TComPic;
1526        m_cIlpPic[j]->create(m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true, m_layerId);
1527        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
1528        {
1529          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
1530        }
1531      }
1532    }
1533
1534    if( m_cVPS.getNumRefLayers( m_layerId ) == 0 )
1535    {
1536      UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId );
1537      RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx));
1538     
1539      if( m_cPPS.getLayerId() == 0 && 
1540          m_cSPS.getLayerId() == 0 &&
1541          repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() &&
1542          repFmt->getSeparateColourPlaneVpsFlag() == 0 &&
1543          repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() &&
1544          repFmt->getPicWidthVpsInLumaSamples()  == m_cSPS.getPicWidthInLumaSamples() &&
1545          repFmt->getBitDepthVpsLuma()   == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) &&
1546          repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) &&
1547          repFmt->getConformanceWindowVps().getWindowLeftOffset()   == m_cSPS.getConformanceWindow().getWindowLeftOffset() &&
1548          repFmt->getConformanceWindowVps().getWindowRightOffset()  == m_cSPS.getConformanceWindow().getWindowRightOffset() &&
1549          repFmt->getConformanceWindowVps().getWindowTopOffset()    == m_cSPS.getConformanceWindow().getWindowTopOffset() &&
1550          repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() )
1551      {
1552        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1);
1553      }
1554      else
1555      {
1556        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0);
1557      }
1558    }
1559  }
1560}
1561
1562Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
1563{
1564  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1565  {
1566    if (layerId == m_refLocationOffsetLayerId[i])
1567    {
1568      return m_scaledRefLayerWindow[i];
1569    }
1570  }
1571
1572  return Window();
1573}
1574
1575Window TEncTop::getRefLayerWindowForLayer(Int layerId)
1576{
1577  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1578  {
1579    if (layerId == m_refLayerId[i])
1580    {
1581      return m_refLayerWindow[i];
1582    }
1583  }
1584
1585  return Window();
1586}
1587#endif //SVC_EXTENSION
1588//! \}
Note: See TracBrowser for help on using the repository browser.