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

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

rename Q0048_CGS_3D_ASYMLUT to CGS_3D_ASYMLUT

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