source: SHVCSoftware/branches/SHM-upgrade/source/Lib/TLibEncoder/TEncTop.cpp @ 989

Last change on this file since 989 was 989, checked in by seregin, 10 years ago

port fix for the ticket #53 (rev 988)

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