source: 3DVCSoftware/branches/HTM-15.1-dev0/source/Lib/TLibEncoder/TEncTop.cpp @ 1327

Last change on this file since 1327 was 1321, checked in by tech, 9 years ago

Merged 15.0-dev0@1320.

  • Property svn:eol-style set to native
File size: 53.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#include "TLibCommon/TComChromaFormat.h"
42#if FAST_BIT_EST
43#include "TLibCommon/ContextModel.h"
44#endif
45#if NH_MV
46#include "../../App/TAppEncoder/TAppEncTop.h"
47#endif
48
49//! \ingroup TLibEncoder
50//! \{
51
52// ====================================================================================================================
53// Constructor / destructor / create / destroy
54// ====================================================================================================================
55
56TEncTop::TEncTop()
57{
58  m_iPOCLast          = -1;
59  m_iNumPicRcvd       =  0;
60  m_uiNumAllPicCoded  =  0;
61  m_pppcRDSbacCoder   =  NULL;
62  m_pppcBinCoderCABAC =  NULL;
63  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
64#if ENC_DEC_TRACE
65  if (g_hTrace == NULL)
66  {
67    g_hTrace = fopen( "TraceEnc.txt", "wb" );
68  }
69  g_bJustDoIt = g_bEncDecTraceDisable;
70  g_nSymbolCounter = 0;
71#endif
72
73  m_iMaxRefPicNum     = 0;
74
75#if FAST_BIT_EST
76  ContextModel::buildNextStateTable();
77#endif
78#if NH_MV
79  m_ivPicLists = NULL;
80#endif
81#if NH_3D_IC
82  m_aICEnableCandidate = NULL;
83  m_aICEnableNum = NULL;
84#endif
85#if NH_MV
86  m_cCavlcCoder.setEncTop(this); 
87#endif
88
89}
90
91TEncTop::~TEncTop()
92{
93#if ENC_DEC_TRACE
94  if (g_hTrace != stdout)
95  {
96    fclose( g_hTrace );
97  }
98#endif
99}
100
101Void TEncTop::create ()
102{
103#if !NH_MV
104  // initialize global variables
105  initROM();
106#endif
107
108  // create processing unit classes
109  m_cGOPEncoder.        create( );
110  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth );
111  m_cCuEncoder.         create( m_maxTotalCUDepth, m_maxCUWidth, m_maxCUHeight, m_chromaFormatIDC );
112  if (m_bUseSAO)
113  {
114    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA], m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] );
115    m_cEncSAO.createEncData(getSaoCtuBoundary());
116  }
117#if ADAPTIVE_QP_SELECTION
118  if (m_bUseAdaptQpSelect)
119  {
120    m_cTrQuant.initSliceQpDelta();
121  }
122#endif
123
124  m_cLoopFilter.create( m_maxTotalCUDepth );
125
126  if ( m_RCEnableRateControl )
127  {
128#if KWU_RC_MADPRED_E0227
129    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
130      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() );
131#else
132    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
133        m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
134#endif
135  }
136
137  m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1];
138#if FAST_BIT_EST
139  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1];
140#else
141  m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1];
142#endif
143
144  for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
145  {
146    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
147#if FAST_BIT_EST
148    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
149#else
150    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
151#endif
152
153    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
154    {
155      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
156#if FAST_BIT_EST
157      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
158#else
159      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
160#endif
161      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
162    }
163  }
164}
165
166Void TEncTop::destroy ()
167{
168  // destroy processing unit classes
169  m_cGOPEncoder.        destroy();
170  m_cSliceEncoder.      destroy();
171  m_cCuEncoder.         destroy();
172  m_cEncSAO.            destroyEncData();
173  m_cEncSAO.            destroy();
174  m_cLoopFilter.        destroy();
175  m_cRateCtrl.          destroy();
176  m_cSearch.            destroy();
177  Int iDepth;
178  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
179  {
180    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
181    {
182      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
183      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
184    }
185  }
186
187  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
188  {
189    delete [] m_pppcRDSbacCoder[iDepth];
190    delete [] m_pppcBinCoderCABAC[iDepth];
191  }
192
193  delete [] m_pppcRDSbacCoder;
194  delete [] m_pppcBinCoderCABAC;
195
196#if !NH_MV
197  // destroy ROM
198  destroyROM();
199#endif
200
201  return;
202}
203
204#if KWU_RC_MADPRED_E0227
205Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding)
206#else
207Void TEncTop::init(Bool isFieldCoding)
208#endif
209{
210  // initialize SPS
211#if H_3D
212  // Assuming that all PPS indirectly refer to the same VPS via different SPS
213  m_cSPS.setVPS(m_cVPS);
214#endif
215  xInitSPS();
216  xInitVPS();
217
218  m_cRdCost.setCostMode(m_costMode);
219
220#if NH_MV
221  // This seems to be incorrect, but irrelevant for the MV-HEVC
222  *(m_cVPS->getPTL()) = *m_cSPS.getPTL();
223  m_cVPS->getTimingInfo()->setTimingInfoPresentFlag       ( false );
224#endif
225  // initialize PPS
226  xInitPPS();
227  xInitRPS(isFieldCoding);
228
229  xInitPPSforTiles();
230#if NH_3D_IC
231  m_aICEnableCandidate = new Int[ 10 ];
232  m_aICEnableNum = new Int[ 10 ];
233
234  for(int i=0;i<10;i++)
235  {
236    m_aICEnableCandidate[i]=0;
237    m_aICEnableNum[i]=0;
238  }
239#endif
240
241  // initialize processing unit classes
242  m_cGOPEncoder.  init( this );
243  m_cSliceEncoder.init( this );
244  m_cCuEncoder.   init( this );
245
246#if KWU_RC_MADPRED_E0227
247  m_pcTAppEncTop = pcTAppEncTop;
248#endif
249  // initialize transform & quantization class
250  m_pcCavlcCoder = getCavlcCoder();
251
252  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
253                   m_useRDOQ,
254                   m_useRDOQTS,
255#if T0196_SELECTIVE_RDOQ
256                   m_useSelectiveRDOQ,
257#endif
258                   true
259                  ,m_useTransformSkipFast
260#if ADAPTIVE_QP_SELECTION
261                  ,m_bUseAdaptQpSelect
262#endif
263                  );
264
265  // initialize encoder search class
266  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
267
268  m_iMaxRefPicNum = 0;
269
270  xInitScalingLists();
271}
272
273Void TEncTop::xInitScalingLists()
274{
275  // Initialise scaling lists
276  // The encoder will only use the SPS scaling lists. The PPS will never be marked present.
277  const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
278  {
279      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
280      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
281  };
282  if(getUseScalingListId() == SCALING_LIST_OFF)
283  {
284    getTrQuant()->setFlatScalingList(maxLog2TrDynamicRange, m_cSPS.getBitDepths());
285    getTrQuant()->setUseScalingList(false);
286    m_cSPS.setScalingListPresentFlag(false);
287    m_cPPS.setScalingListPresentFlag(false);
288  }
289  else if(getUseScalingListId() == SCALING_LIST_DEFAULT)
290  {
291    m_cSPS.getScalingList().setDefaultScalingList ();
292    m_cSPS.setScalingListPresentFlag(false);
293    m_cPPS.setScalingListPresentFlag(false);
294
295    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths());
296    getTrQuant()->setUseScalingList(true);
297  }
298  else if(getUseScalingListId() == SCALING_LIST_FILE_READ)
299  {
300    m_cSPS.getScalingList().setDefaultScalingList ();
301    if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile()))
302    {
303      Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string
304      assert(bParsedScalingList);
305      exit(1);
306    }
307    m_cSPS.getScalingList().checkDcOfMatrix();
308    m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList());
309    m_cPPS.setScalingListPresentFlag(false);
310    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths());
311    getTrQuant()->setUseScalingList(true);
312  }
313  else
314  {
315    printf("error : ScalingList == %d not supported\n",getUseScalingListId());
316    assert(0);
317  }
318
319  if (getUseScalingListId() != SCALING_LIST_OFF)
320  { 
321    // Prepare delta's:
322  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
323  {
324    const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
325
326    for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep)
327    {
328      m_cSPS.getScalingList().checkPredMode( sizeId, listId );
329    }
330  }
331  }
332}
333
334// ====================================================================================================================
335// Public member functions
336// ====================================================================================================================
337
338#if NH_MV
339Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg )
340{
341  TComPic* pcPicCurr = NULL;
342
343  // get original YUV
344  xGetNewPicBuffer( pcPicCurr );
345  pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
346
347  // compute image characteristics
348  if ( getUseAdaptiveQP() )
349  {
350    m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
351  }
352  pcPicCurr->setLayerId( getLayerId()); 
353#if NH_3D
354  pcPicCurr->setScaleOffset( m_cameraParameters->getCodedScale(), m_cameraParameters->getCodedOffset() );
355#endif
356}
357#endif
358
359Void TEncTop::deletePicBuffer()
360{
361
362#if !NH_MV
363  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
364  Int iSize = Int( m_cListPic.size() );
365  for ( Int i = 0; i < iSize; i++ )
366  {
367    TComPic* pcPic = *(iterPic++);
368
369    pcPic->destroy();
370    delete pcPic;
371    pcPic = NULL;
372  }
373#endif
374}
375
376/**
377 - Application has picture buffer list with size of GOP + 1
378 - Picture buffer list acts like as ring buffer
379 - End of the list has the latest picture
380 .
381 \param   flush               cause encoder to encode a partial GOP
382 \param   pcPicYuvOrg         original YUV picture
383 \param   pcPicYuvTrueOrg     
384 \param   snrCSC
385 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
386 \retval  accessUnitsOut      list of output access units
387 \retval  iNumEncoded         number of encoded pictures
388 */
389#if NH_MV
390Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Int gopId )
391{
392#else
393Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
394{
395#endif
396#if NH_3D
397  TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() );
398  if( picLastCoded )
399  {
400    picLastCoded->compressMotion(1); 
401  }
402#endif
403#if NH_MV
404  if( gopId == 0)
405  {
406    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, *(m_ivPicLists->getSubDpb( getLayerId(), false )), rcListPicYuvRecOut, accessUnitsOut); 
407#else
408  if (pcPicYuvOrg != NULL)
409  {
410    // get original YUV
411    TComPic* pcPicCurr = NULL;
412
413    xGetNewPicBuffer( pcPicCurr );
414    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
415    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
416
417    // compute image characteristics
418    if ( getUseAdaptiveQP() )
419    {
420      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
421    }
422  }
423
424  if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0)))
425  {
426    iNumEncoded = 0;
427    return;
428  }
429#endif
430  if ( m_RCEnableRateControl )
431  {
432    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
433  }
434#if NH_MV
435  }
436  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, *(m_ivPicLists->getSubDpb(getLayerId(), false) ), rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE, gopId);
437
438  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
439  {
440#else
441  // compress GOP
442  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
443#endif
444  if ( m_RCEnableRateControl )
445  {
446    m_cRateCtrl.destroyRCGOP();
447  }
448
449  iNumEncoded         = m_iNumPicRcvd;
450  m_iNumPicRcvd       = 0;
451  m_uiNumAllPicCoded += iNumEncoded;
452#if NH_MV
453}
454#endif
455}
456
457/**------------------------------------------------
458 Separate interlaced frame into two fields
459 -------------------------------------------------**/
460Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
461{
462  if (!isTop)
463  {
464    org += stride;
465  }
466  for (Int y = 0; y < height>>1; y++)
467  {
468    for (Int x = 0; x < width; x++)
469    {
470      dstField[x] = org[x];
471    }
472
473    dstField += stride;
474    org += stride*2;
475  }
476
477}
478#if NH_MV
479Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff, Int gopId )
480{
481  assert( 0 ); // Field coding and multiview need to be further harmonized.
482}
483#else
484Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
485{
486  iNumEncoded = 0;
487
488  for (Int fieldNum=0; fieldNum<2; fieldNum++)
489  {
490    if (pcPicYuvOrg)
491    {
492
493      /* -- field initialization -- */
494      const Bool isTopField=isTff==(fieldNum==0);
495
496      TComPic *pcField;
497      xGetNewPicBuffer( pcField );
498      pcField->setReconMark (false);                     // where is this normally?
499
500      if (fieldNum==1)                                   // where is this normally?
501      {
502        TComPicYuv* rpcPicYuvRec;
503
504        // org. buffer
505        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.
506        {
507          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
508        }
509        else
510        {
511          rpcPicYuvRec = new TComPicYuv;
512          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true);
513        }
514        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
515      }
516
517      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
518      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
519
520      pcField->setTopField(isTopField);                  // interlaced requirement
521
522      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
523      {
524        const ComponentID component = ComponentID(componentIndex);
525        const UInt stride = pcPicYuvOrg->getStride(component);
526
527        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
528                       pcField->getPicYuvOrg()->getAddr(component),
529                       pcPicYuvOrg->getStride(component),
530                       pcPicYuvOrg->getWidth(component),
531                       pcPicYuvOrg->getHeight(component),
532                       isTopField);
533
534        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
535                       pcField->getPicYuvTrueOrg()->getAddr(component),
536                       pcPicYuvTrueOrg->getStride(component),
537                       pcPicYuvTrueOrg->getWidth(component),
538                       pcPicYuvTrueOrg->getHeight(component),
539                       isTopField);
540      }
541
542      // compute image characteristics
543      if ( getUseAdaptiveQP() )
544      {
545        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
546      }
547    }
548
549    if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
550    {
551      // compress GOP
552      m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
553
554      iNumEncoded += m_iNumPicRcvd;
555      m_uiNumAllPicCoded += m_iNumPicRcvd;
556      m_iNumPicRcvd = 0;
557    }
558  }
559}
560#endif
561// ====================================================================================================================
562// Protected member functions
563// ====================================================================================================================
564
565/**
566 - Application has picture buffer list with size of GOP + 1
567 - Picture buffer list acts like as ring buffer
568 - End of the list has the latest picture
569 .
570 \retval rpcPic obtained picture buffer
571 */
572Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
573{
574  // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
575
576#if NH_MV
577  TComList<TComPic*>& cListPic = *(m_ivPicLists->getSubDpb(getLayerId(), false) );
578  TComSlice::sortPicList(cListPic);
579#else
580  TComSlice::sortPicList(m_cListPic);
581#endif
582
583
584#if NH_MV
585  if (cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
586  {
587    TComList<TComPic*>::iterator iterPic  = cListPic.begin();
588    Int iSize = Int( cListPic.size() );
589#else
590  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
591  {
592    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
593    Int iSize = Int( m_cListPic.size() );
594#endif
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      pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false);
610      rpcPic = pcEPic;
611    }
612    else
613    {
614      rpcPic = new TComPic;
615      rpcPic->create( m_cSPS, m_cPPS, false );
616    }
617
618#if NH_MV
619    cListPic.pushBack( rpcPic );
620#else
621    m_cListPic.pushBack( rpcPic );
622#endif
623  }
624  rpcPic->setReconMark (false);
625
626  m_iPOCLast++;
627  m_iNumPicRcvd++;
628
629  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
630  // mark it should be extended
631  rpcPic->getPicYuvRec()->setBorderExtension(false);
632#if NH_MV
633  rpcPic->getPicYuvOrg()->setBorderExtension(false);
634#endif
635
636}
637
638Void TEncTop::xInitVPS()
639{
640  // The SPS must have already been set up.
641  // set the VPS profile information.
642#if NH_MV
643  // Do initialization in TAppEncTop
644#else
645  *m_cVPS.getPTL() = *m_cSPS.getPTL();
646  m_cVPS.setMaxOpSets(1);
647  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
648  m_cVPS.setNumHrdParameters( 0 );
649
650  m_cVPS.createHrdParamBuffer();
651  for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ )
652  {
653    m_cVPS.setHrdOpSetIdx( 0, i );
654    m_cVPS.setCprmsPresentFlag( false, i );
655    // Set up HrdParameters here.
656  }
657#endif
658}
659
660Void TEncTop::xInitSPS()
661{
662#if NH_MV
663  m_cSPS.setSPSId( getLayerIdInVps() );
664  m_cSPS.setLayerId( getLayerId() );
665 // Code below needs to be moved to VPS
666#endif
667  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
668  profileTierLevel.setLevelIdc(m_level);
669  profileTierLevel.setTierFlag(m_levelTier);
670  profileTierLevel.setProfileIdc(m_profile);
671  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
672  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
673  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
674  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
675  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
676  profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue);
677  profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue);
678  profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag);
679  profileTierLevel.setOnePictureOnlyConstraintFlag(m_onePictureOnlyConstraintFlag);
680  profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag);
681
682  if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8))
683  {
684    /* The above constraint is equal to Profile::MAIN */
685    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
686  }
687  if (m_profile == Profile::MAIN)
688  {
689    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
690    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
691  }
692  /* XXX: should Main be marked as compatible with still picture? */
693  /* XXX: may be a good idea to refactor the above into a function
694   * that chooses the actual compatibility based upon options */
695#if NH_MV 
696  m_cSPS.setUpdateRepFormatFlag           ( false );   
697  Bool multiLayerExtensionFlag  = ( getLayerId() > 0 ) && ( m_cVPS->getNumRefLayers( getLayerId() ) > 0 ); 
698 
699  m_cSPS.setSpsExtOrMaxSubLayersMinus1( multiLayerExtensionFlag ? 7 : m_maxTempLayer - 1 );
700  if ( multiLayerExtensionFlag )
701  {
702    m_cSPS.setSpsInferScalingListFlag   ( true ); 
703    m_cSPS.setSpsScalingListRefLayerId( m_cVPS->getIdRefLayer( getLayerId(), 0 ) ); 
704#if NH_MV
705    if ( m_bUseDisparitySearchRangeRestriction )
706    {
707      m_cSPS.setInterViewMvVertConstraintFlag ( true ) ;
708    }
709#endif
710  } 
711  m_cSPS.setSpsExtensionPresentFlag       ( true ); 
712  m_cSPS.setSpsMultilayerExtensionFlag    ( true ); 
713#if NH_3D
714  m_cSPS.setSps3dExtensionFlag            ( true ); 
715#endif
716#endif
717
718  m_cSPS.setPicWidthInLumaSamples  ( m_iSourceWidth      );
719  m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight     );
720  m_cSPS.setConformanceWindow      ( m_conformanceWindow );
721  m_cSPS.setMaxCUWidth             ( m_maxCUWidth        );
722  m_cSPS.setMaxCUHeight            ( m_maxCUHeight       );
723  m_cSPS.setMaxTotalCUDepth        ( m_maxTotalCUDepth   );
724#if NH_3D
725  assert( !getIsDepth()  || m_chromaFormatIDC == CHROMA_400 ); 
726#endif
727  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
728  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize);
729
730  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() );
731  Int log2MinCUSize = 0;
732  while(minCUSize > 1)
733  {
734    minCUSize >>= 1;
735    log2MinCUSize++;
736  }
737
738  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
739
740  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
741  m_cSPS.setUsePCM        ( m_usePCM           );
742  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
743
744  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
745  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
746  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
747  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
748
749  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
750
751  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
752
753  m_cSPS.setUseAMP ( m_useAMP );
754
755  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
756  {
757    m_cSPS.setBitDepth      (ChannelType(channelType), m_bitDepth[channelType] );
758#if O0043_BEST_EFFORT_DECODING
759    m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] );
760#endif
761    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8)));
762    m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType]         );
763  }
764#if NH_MV
765  m_cSPS.inferRepFormat( m_cVPS, getLayerId(), true ); 
766#endif
767m_cSPS.setUseSAO( m_bUseSAO );
768
769  m_cSPS.setMaxTLayers( m_maxTempLayer );
770  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
771
772  for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
773  {
774    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
775    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
776  }
777#if NH_MV
778  for ( Int ols = 0; ols < m_cVPS->getNumOutputLayerSets(); ols++)
779  {
780    // Check MaxDecPicBuffering
781    const std::vector<Int>& targetDecLayerIdList = m_cVPS->getTargetDecLayerIdList( m_cVPS->olsIdxToLsIdx( ols )); 
782    for( Int is = 0; is < targetDecLayerIdList.size(); is++  )
783    {
784      if ( m_cVPS->getNecessaryLayerFlag( ols, is ) )
785      {     
786        m_cSPS.inferSpsMaxDecPicBufferingMinus1( m_cVPS, ols, targetDecLayerIdList[is], true );       
787      }
788    }
789  }
790#endif
791
792
793  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
794  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
795  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
796  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
797
798  if (m_cSPS.getVuiParametersPresentFlag())
799  {
800    TComVUI* pcVUI = m_cSPS.getVuiParameters();
801    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
802    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
803    pcVUI->setSarWidth(getSarWidth());
804    pcVUI->setSarHeight(getSarHeight());
805    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
806    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
807#if NH_MV
808    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 );
809#else
810    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
811#endif
812    pcVUI->setVideoFormat(getVideoFormat());
813    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
814    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
815    pcVUI->setColourPrimaries(getColourPrimaries());
816    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
817    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
818    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
819    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
820    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
821    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
822    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
823    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
824    pcVUI->setFieldSeqFlag(false);
825    pcVUI->setHrdParametersPresentFlag(false);
826    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
827    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
828    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
829    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
830    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
831    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
832    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
833    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
834    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
835    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
836  }
837  m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
838  assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS);
839  for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
840  {
841    m_cSPS.setLtRefPicPocLsbSps(k, 0);
842    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
843  }
844  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
845  {
846    xInitHrdParameters();
847  }
848  if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
849  {
850    m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true );
851  }
852
853  // Set up SPS range extension settings
854  m_cSPS.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag);
855  m_cSPS.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag);
856  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
857  {
858    m_cSPS.getSpsRangeExtension().setRdpcmEnabledFlag(RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]);
859  }
860  m_cSPS.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag);
861  m_cSPS.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag );
862  m_cSPS.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag);
863  m_cSPS.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag);
864  m_cSPS.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag);
865#if NH_MV
866  m_cSPS.setSpsRangeExtensionsFlag( m_cSPS.getSpsRangeExtension().settingsDifferFromDefaults() );
867#endif
868
869}
870
871Void TEncTop::xInitHrdParameters()
872{
873  Bool useSubCpbParams = (getSliceMode() > 0) || (getSliceSegmentMode() > 0);
874  Int  bitRate         = getTargetBitrate();
875  Bool isRandomAccess  = getIntraPeriod() > 0;
876
877  if( !getVuiParametersPresentFlag() )
878  {
879    return;
880  }
881
882  TComVUI *vui = m_cSPS.getVuiParameters();
883  TComHRD *hrd = vui->getHrdParameters();
884
885  TimingInfo *timingInfo = vui->getTimingInfo();
886  timingInfo->setTimingInfoPresentFlag( true );
887  switch( getFrameRate() )
888  {
889  case 24:
890    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
891    break;
892  case 25:
893    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
894    break;
895  case 30:
896    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
897    break;
898  case 50:
899    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
900    break;
901  case 60:
902    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
903    break;
904  default:
905    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
906    break;
907  }
908
909  Bool rateCnt = ( bitRate > 0 );
910  hrd->setNalHrdParametersPresentFlag( rateCnt );
911  hrd->setVclHrdParametersPresentFlag( rateCnt );
912
913  hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams );
914
915  if( hrd->getSubPicCpbParamsPresentFlag() )
916  {
917    hrd->setTickDivisorMinus2( 100 - 2 );                          //
918    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
919    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
920    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
921  }
922  else
923  {
924    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );
925  }
926
927  hrd->setBitRateScale( 4 );                                       // in units of 2^( 6 + 4 ) = 1,024 bps
928  hrd->setCpbSizeScale( 6 );                                       // in units of 2^( 4 + 6 ) = 1,024 bit
929  hrd->setDuCpbSizeScale( 6 );                                     // in units of 2^( 4 + 6 ) = 1,024 bit
930
931  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
932  if( isRandomAccess )
933  {
934    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
935    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
936  }
937  else
938  {
939    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
940    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
941  }
942
943  // Note: parameters for all temporal layers are initialized with the same values
944  Int i, j;
945  UInt bitrateValue, cpbSizeValue;
946  UInt duCpbSizeValue;
947  UInt duBitRateValue = 0;
948
949  for( i = 0; i < MAX_TLAYER; i ++ )
950  {
951    hrd->setFixedPicRateFlag( i, 1 );
952    hrd->setPicDurationInTcMinus1( i, 0 );
953    hrd->setLowDelayHrdFlag( i, 0 );
954    hrd->setCpbCntMinus1( i, 0 );
955
956    //! \todo check for possible PTL violations
957    // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale )
958    bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) );      // bitRate is in bits, so it needs to be scaled down
959    // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale )
960    cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) );      // using bitRate results in 1 second CPB size
961
962    // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know
963    // in how many DUs the slice segment settings will result
964    duCpbSizeValue = bitrateValue;
965    duBitRateValue = cpbSizeValue;
966
967    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
968    {
969      hrd->setBitRateValueMinus1( i, j, 0, ( bitrateValue - 1 ) );
970      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
971      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) );
972      hrd->setDuBitRateValueMinus1( i, j, 0, ( duBitRateValue - 1 ) );
973      hrd->setCbrFlag( i, j, 0, false );
974
975      hrd->setBitRateValueMinus1( i, j, 1, ( bitrateValue - 1) );
976      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
977      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( duCpbSizeValue - 1 ) );
978      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
979      hrd->setCbrFlag( i, j, 1, false );
980    }
981  }
982}
983
984
985Void TEncTop::xInitPPS()
986{
987#if NH_MV
988  m_cPPS.setLayerId( getLayerId() );
989#if NH_3D
990  // Check if this condition is still correct
991  if( getVPS()->getNumRefListLayers( getLayerId() ) > 0 )
992#else
993  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
994#endif
995  {
996    m_cPPS.setListsModificationPresentFlag( true );
997  }
998  m_cPPS.setPPSId( getLayerIdInVps() );
999  m_cPPS.setSPSId( getLayerIdInVps() );
1000  m_cPPS.setPpsMultilayerExtensionFlag    ( true ); 
1001#if NH_3D
1002  // Might be used for DLT
1003  m_cPPS.setPps3dExtensionFlag            ( getIsDepth() ); 
1004#endif
1005#endif
1006
1007#if NH_3D_DLT
1008  // create mapping from depth layer indexes to layer ids
1009  Int j=0;
1010  for( Int i=0; i<=getVPS()->getMaxLayersMinus1(); i++ )
1011  {
1012    Int layerId = getVPS()->getLayerIdInNuh(i);
1013    if( getVPS()->getDepthId(layerId) )
1014      m_cDLT.setDepthIdxToLayerId(j++, layerId);
1015  }
1016  m_cPPS.setDLT( m_cDLT );
1017#endif
1018
1019  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1020  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1021
1022  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1023  {
1024    bUseDQP = true;
1025  }
1026
1027  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
1028  {
1029    bUseDQP=false;
1030  }
1031
1032
1033  if ( m_RCEnableRateControl )
1034  {
1035    m_cPPS.setUseDQP(true);
1036    m_cPPS.setMaxCuDQPDepth( 0 );
1037  }
1038  else if(bUseDQP)
1039  {
1040    m_cPPS.setUseDQP(true);
1041    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1042  }
1043  else
1044  {
1045    m_cPPS.setUseDQP(false);
1046    m_cPPS.setMaxCuDQPDepth( 0 );
1047  }
1048
1049  if ( m_diffCuChromaQpOffsetDepth >= 0 )
1050  {
1051    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth);
1052    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1053    m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6);
1054    /* todo, insert table entries from command line (NB, 0 should not be touched) */
1055  }
1056  else
1057  {
1058    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0);
1059    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1060  }
1061  m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag);
1062  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA,   m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA  ]);
1063  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]);
1064
1065  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1066  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
1067
1068  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1069  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1070  m_cPPS.setUseWP( m_useWeightedPred );
1071  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1072  m_cPPS.setOutputFlagPresentFlag( false );
1073#if NH_MV
1074  m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
1075#endif
1076  m_cPPS.setSignHideFlag(getSignHideFlag());
1077  if ( getDeblockingFilterMetric() )
1078  {
1079    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1080    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1081  }
1082  else
1083  {
1084      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1085      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1086    }
1087
1088  if (! m_cPPS.getPicDisableDeblockingFilterFlag())
1089  {
1090    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1091    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
1092  }
1093  else
1094  {
1095    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1096    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1097  }
1098
1099  // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values:
1100  const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() ||
1101                                                  m_cPPS.getPicDisableDeblockingFilterFlag()      ||
1102                                                  m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 ||
1103                                                  m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0;
1104
1105  m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag);
1106
1107  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1108  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1109  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1110
1111
1112  Int histogram[MAX_NUM_REF + 1];
1113  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1114  {
1115    histogram[i]=0;
1116  }
1117  for( Int i = 0; i < getGOPSize(); i++)
1118  {
1119    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1120    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1121  }
1122
1123  Int maxHist=-1;
1124  Int bestPos=0;
1125  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1126  {
1127    if(histogram[i]>maxHist)
1128    {
1129      maxHist=histogram[i];
1130      bestPos=i;
1131    }
1132  }
1133  assert(bestPos <= 15);
1134  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1135  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1136  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1137  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1138  m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize  );
1139
1140  if (m_sliceSegmentMode != NO_SLICES)
1141  {
1142    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1143  }
1144}
1145
1146//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1147Void TEncTop::xInitRPS(Bool isFieldCoding)
1148{
1149  TComReferencePictureSet*      rps;
1150
1151  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
1152  TComRPSList* rpsList = m_cSPS.getRPSList();
1153
1154  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
1155  {
1156    GOPEntry ge = getGOPEntry(i);
1157    rps = rpsList->getReferencePictureSet(i);
1158    rps->setNumberOfPictures(ge.m_numRefPics);
1159    rps->setNumRefIdc(ge.m_numRefIdc);
1160    Int numNeg = 0;
1161    Int numPos = 0;
1162    for( Int j = 0; j < ge.m_numRefPics; j++)
1163    {
1164      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1165      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1166      if(ge.m_referencePics[j]>0)
1167      {
1168        numPos++;
1169      }
1170      else
1171      {
1172        numNeg++;
1173      }
1174    }
1175    rps->setNumberOfNegativePictures(numNeg);
1176    rps->setNumberOfPositivePictures(numPos);
1177
1178    // handle inter RPS intialization from the config file.
1179    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1180    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1181    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
1182
1183    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1184    {
1185      assert (RPSRef!=NULL);
1186      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1187      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1188
1189      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1190      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1191      Int count=0;
1192      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1193      {
1194        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1195        rps->setRefIdc(j, 0);
1196        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1197        {
1198          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1199          {
1200              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1201              count++;
1202              break;
1203          }
1204        }
1205      }
1206      if (count != rps->getNumberOfPictures())
1207      {
1208        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");
1209        rps->setInterRPSPrediction(0);
1210      }
1211    }
1212    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1213    {
1214      assert (RPSRef!=NULL);
1215      rps->setDeltaRPS(ge.m_deltaRPS);
1216      rps->setNumRefIdc(ge.m_numRefIdc);
1217      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1218      {
1219        rps->setRefIdc(j, ge.m_refIdc[j]);
1220      }
1221      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
1222      // computed from the RefIdc.  A warning is printed if they are not identical.
1223      numNeg = 0;
1224      numPos = 0;
1225      TComReferencePictureSet      RPSTemp;  // temporary variable
1226
1227      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1228      {
1229        if (ge.m_refIdc[j])
1230        {
1231          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1232          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1233          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1234          if (deltaPOC<0)
1235          {
1236            numNeg++;
1237          }
1238          else
1239          {
1240            numPos++;
1241          }
1242        }
1243      }
1244      if (numNeg != rps->getNumberOfNegativePictures())
1245      {
1246        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1247        rps->setNumberOfNegativePictures(numNeg);
1248        rps->setNumberOfPictures(numNeg+numPos);
1249      }
1250      if (numPos != rps->getNumberOfPositivePictures())
1251      {
1252        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1253        rps->setNumberOfPositivePictures(numPos);
1254        rps->setNumberOfPictures(numNeg+numPos);
1255      }
1256      RPSTemp.setNumberOfPictures(numNeg+numPos);
1257      RPSTemp.setNumberOfNegativePictures(numNeg);
1258      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1259      // check if Delta POC and Used are the same
1260      // print warning if they are not.
1261      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1262      {
1263        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1264        {
1265          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1266          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1267        }
1268        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1269        {
1270          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1271          rps->setUsed(j,RPSTemp.getUsed(j));
1272        }
1273      }
1274    }
1275  }
1276  //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.
1277  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1278  if (isFieldCoding)
1279  {
1280    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1281    rps->setNumberOfPictures(1);
1282    rps->setNumberOfNegativePictures(1);
1283    rps->setNumberOfPositivePictures(0);
1284    rps->setNumberOfLongtermPictures(0);
1285    rps->setDeltaPOC(0,-1);
1286    rps->setPOC(0,0);
1287    rps->setUsed(0,true);
1288    rps->setInterRPSPrediction(false);
1289    rps->setDeltaRIdxMinus1(0);
1290    rps->setDeltaRPS(0);
1291    rps->setNumRefIdc(0);
1292  }
1293}
1294
1295   // This is a function that
1296   // determines what Reference Picture Set to use
1297   // for a specific slice (with POC = POCCurr)
1298Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1299{
1300#if NH_MV
1301  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
1302  {
1303    TComReferencePictureSet* rps = slice->getLocalRPS();
1304    rps->setNumberOfNegativePictures(0);
1305    rps->setNumberOfPositivePictures(0);
1306    rps->setNumberOfLongtermPictures(0);
1307    rps->setNumberOfPictures(0);
1308    slice->setRPS(rps);
1309  }
1310  else
1311  {
1312#endif
1313  slice->setRPSidx(GOPid);
1314
1315  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1316  {
1317    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1318    {
1319      Int POCIndex = POCCurr%m_uiIntraPeriod;
1320      if(POCIndex == 0)
1321      {
1322        POCIndex = m_uiIntraPeriod;
1323      }
1324      if(POCIndex == m_GOPList[extraNum].m_POC)
1325      {
1326        slice->setRPSidx(extraNum);
1327      }
1328    }
1329    else
1330    {
1331      if(POCCurr==m_GOPList[extraNum].m_POC)
1332      {
1333        slice->setRPSidx(extraNum);
1334      }
1335    }
1336  }
1337
1338  if(POCCurr == 1 && slice->getPic()->isField())
1339  {
1340    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1341  }
1342
1343  const TComReferencePictureSet *rps = (slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1344  slice->setRPS(rps);
1345#if NH_MV
1346  }
1347#endif
1348
1349}
1350
1351Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid )
1352{
1353  Int rpsIdx = GOPid;
1354
1355  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1356  {
1357    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1358    {
1359      Int POCIndex = POCCurr%m_uiIntraPeriod;
1360      if(POCIndex == 0)
1361      {
1362        POCIndex = m_uiIntraPeriod;
1363      }
1364      if(POCIndex == m_GOPList[extraNum].m_POC)
1365      {
1366        rpsIdx = extraNum;
1367      }
1368    }
1369    else
1370    {
1371      if(POCCurr==m_GOPList[extraNum].m_POC)
1372      {
1373        rpsIdx = extraNum;
1374      }
1375    }
1376  }
1377
1378  return rpsIdx;
1379}
1380
1381Void  TEncTop::xInitPPSforTiles()
1382{
1383  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1384  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1385  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1386  if( !m_tileUniformSpacingFlag )
1387  {
1388    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1389    m_cPPS.setTileRowHeight( m_tileRowHeight );
1390  }
1391  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1392
1393  // # substreams is "per tile" when tiles are independent.
1394}
1395
1396Void  TEncCfg::xCheckGSParameters()
1397{
1398  Int   iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth;
1399  Int   iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight;
1400  UInt  uiCummulativeColumnWidth = 0;
1401  UInt  uiCummulativeRowHeight = 0;
1402
1403  //check the column relative parameters
1404  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1405  {
1406    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1407    exit( EXIT_FAILURE );
1408  }
1409
1410  if( m_iNumColumnsMinus1 >= iWidthInCU )
1411  {
1412    printf( "The current picture can not have so many columns.\n" );
1413    exit( EXIT_FAILURE );
1414  }
1415
1416  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1417  {
1418    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1419    {
1420      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1421    }
1422
1423    if( uiCummulativeColumnWidth >= iWidthInCU )
1424    {
1425      printf( "The width of the column is too large.\n" );
1426      exit( EXIT_FAILURE );
1427    }
1428  }
1429
1430  //check the row relative parameters
1431  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1432  {
1433    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1434    exit( EXIT_FAILURE );
1435  }
1436
1437  if( m_iNumRowsMinus1 >= iHeightInCU )
1438  {
1439    printf( "The current picture can not have so many rows.\n" );
1440    exit( EXIT_FAILURE );
1441  }
1442
1443  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1444  {
1445    for(Int i=0; i<m_iNumRowsMinus1; i++)
1446    {
1447      uiCummulativeRowHeight += m_tileRowHeight[i];
1448    }
1449
1450    if( uiCummulativeRowHeight >= iHeightInCU )
1451    {
1452      printf( "The height of the row is too large.\n" );
1453      exit( EXIT_FAILURE );
1454    }
1455  }
1456}
1457
1458#if NH_MV
1459Int TEncTop::getFrameId(Int iGOPid) 
1460{
1461  if(m_iPOCLast == 0)
1462  {
1463    return(0 );
1464  }
1465  else
1466  {
1467    return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ;
1468  }
1469}
1470
1471TComPic* TEncTop::getPic( Int poc )
1472{
1473  TComList<TComPic*>* listPic = getListPic();
1474  TComPic* pcPic = NULL;
1475  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1476  {
1477    if( (*it)->getPOC() == poc )
1478    {
1479      pcPic = *it ;
1480      break ;
1481    }
1482  }
1483  return pcPic;
1484}
1485
1486#endif
1487
1488#if NH_3D_VSO
1489Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset, Int maxCuHeight )
1490{
1491  TRenModel* rendererModel = m_cRdCost.getRenModel(); 
1492  rendererModel->setupPart( iHorOffset, std::min( maxCuHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; 
1493 
1494  Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ];
1495
1496  // setup base views
1497  Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent );
1498
1499  for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ )
1500  {
1501    Int iBaseViewSIdx;
1502    Int iVideoDistMode;
1503    Int iDepthDistMode;
1504
1505    m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode );
1506
1507    AOT( iVideoDistMode < 0 || iVideoDistMode > 2 );
1508
1509    Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ];
1510
1511    TComPicYuv* pcPicYuvVideoRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true  );
1512    TComPicYuv* pcPicYuvDepthRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true  );
1513    TComPicYuv* pcPicYuvVideoOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false );
1514    TComPicYuv* pcPicYuvDepthOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false );   
1515
1516    TComPicYuv* pcPicYuvVideoRef  = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg  : NULL;
1517    TComPicYuv* pcPicYuvDepthRef  = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg  : NULL;
1518
1519    TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg  : pcPicYuvVideoRec;
1520    TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg  : pcPicYuvDepthRec;
1521
1522    AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) );
1523    AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) );
1524    AOT( pcPicYuvDepthTest == NULL );
1525    AOT( pcPicYuvVideoTest == NULL );
1526
1527    rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef );
1528  }
1529
1530  rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 );
1531  // setup virtual views
1532  Int iNumOfSV  = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent );
1533  for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
1534  {
1535    Int iOrgRefBaseViewSIdx;
1536    Int iLeftBaseViewSIdx;
1537    Int iRightBaseViewSIdx;
1538    Int iSynthViewRelNum;
1539    Int iModelNum;
1540    Int iBlendMode;
1541    m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
1542
1543    Int iLeftBaseViewIdx    = -1;
1544    Int iRightBaseViewIdx   = -1;
1545
1546    TComPicYuv* pcPicYuvOrgRef  = NULL;
1547    Int**      ppiShiftLUTLeft  = NULL;
1548    Int**      ppiShiftLUTRight = NULL;
1549    Int**      ppiBaseShiftLUTLeft  = NULL;
1550    Int**      ppiBaseShiftLUTRight = NULL;
1551
1552
1553    Int        iDistToLeft      = -1;
1554
1555    Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum );
1556
1557    if ( iLeftBaseViewSIdx != -1 )
1558    {
1559      iLeftBaseViewIdx   = m_cameraParameters->getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
1560      ppiShiftLUTLeft    = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
1561    }
1562
1563    if ( iRightBaseViewSIdx != -1 )
1564    {
1565      iRightBaseViewIdx  = m_cameraParameters->getBaseSortedId2Id()   [iRightBaseViewSIdx ];
1566      ppiShiftLUTRight   = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
1567    }
1568
1569    if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
1570    {
1571      iDistToLeft          = m_cameraParameters->getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
1572      ppiBaseShiftLUTLeft  = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
1573      ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
1574
1575    }
1576
1577    if ( iOrgRefBaseViewSIdx != -1 )
1578    {
1579      pcPicYuvOrgRef = m_ivPicLists->getPicYuv(  m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false );
1580      AOF ( pcPicYuvOrgRef );
1581    }
1582
1583    rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
1584  }
1585}
1586#endif
1587
1588//! \}
Note: See TracBrowser for help on using the repository browser.