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

Last change on this file since 1114 was 1093, checked in by seregin, 9 years ago

cleanup macros: POC_RESET_RPS, PREVTID0_POC_RESET, POC_RESET_FLAG

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