source: 3DVCSoftware/branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncTop.cpp @ 1288

Last change on this file since 1288 was 1287, checked in by tech, 9 years ago

Upgrade to HM-16.6.

  • Property svn:eol-style set to native
File size: 53.1 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_3D
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#if NH_MV
353  pcPicCurr->setLayerId( getLayerId()); 
354#endif
355#if NH_3D
356  pcPicCurr->setScaleOffset( m_cameraParameters->getCodedScale(), m_cameraParameters->getCodedOffset() );
357#endif
358}
359#endif
360
361Void TEncTop::deletePicBuffer()
362{
363  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
364  Int iSize = Int( m_cListPic.size() );
365
366  for ( Int i = 0; i < iSize; i++ )
367  {
368    TComPic* pcPic = *(iterPic++);
369
370    pcPic->destroy();
371    delete pcPic;
372    pcPic = NULL;
373  }
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_cListPic, 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_cListPic, 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  TComSlice::sortPicList(m_cListPic);
577
578
579  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
580  {
581    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
582    Int iSize = Int( m_cListPic.size() );
583    for ( Int i = 0; i < iSize; i++ )
584    {
585      rpcPic = *(iterPic++);
586      if(rpcPic->getSlice(0)->isReferenced() == false)
587      {
588        break;
589      }
590    }
591  }
592  else
593  {
594    if ( getUseAdaptiveQP() )
595    {
596      TEncPic* pcEPic = new TEncPic;
597      pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false);
598      rpcPic = pcEPic;
599    }
600    else
601    {
602      rpcPic = new TComPic;
603      rpcPic->create( m_cSPS, m_cPPS, false );
604    }
605
606    m_cListPic.pushBack( rpcPic );
607  }
608  rpcPic->setReconMark (false);
609
610  m_iPOCLast++;
611  m_iNumPicRcvd++;
612
613  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
614  // mark it should be extended
615  rpcPic->getPicYuvRec()->setBorderExtension(false);
616#if NH_MV
617  rpcPic->getPicYuvOrg()->setBorderExtension(false);
618#endif
619
620}
621
622Void TEncTop::xInitVPS()
623{
624  // The SPS must have already been set up.
625  // set the VPS profile information.
626#if NH_MV
627  // Do initialization in TAppEncTop
628#else
629  *m_cVPS.getPTL() = *m_cSPS.getPTL();
630  m_cVPS.setMaxOpSets(1);
631  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
632  m_cVPS.setNumHrdParameters( 0 );
633
634  m_cVPS.createHrdParamBuffer();
635  for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ )
636  {
637    m_cVPS.setHrdOpSetIdx( 0, i );
638    m_cVPS.setCprmsPresentFlag( false, i );
639    // Set up HrdParameters here.
640  }
641#endif
642}
643
644Void TEncTop::xInitSPS()
645{
646#if NH_MV
647  m_cSPS.setSPSId( getLayerIdInVps() );
648  m_cSPS.setLayerId( getLayerId() );
649 // Code below needs to be moved to VPS
650#endif
651  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
652  profileTierLevel.setLevelIdc(m_level);
653  profileTierLevel.setTierFlag(m_levelTier);
654  profileTierLevel.setProfileIdc(m_profile);
655  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
656  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
657  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
658  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
659  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
660  profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue);
661  profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue);
662  profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag);
663  profileTierLevel.setOnePictureOnlyConstraintFlag(m_onePictureOnlyConstraintFlag);
664  profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag);
665
666  if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8))
667  {
668    /* The above constraint is equal to Profile::MAIN */
669    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
670  }
671  if (m_profile == Profile::MAIN)
672  {
673    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
674    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
675  }
676  /* XXX: should Main be marked as compatible with still picture? */
677  /* XXX: may be a good idea to refactor the above into a function
678   * that chooses the actual compatibility based upon options */
679#if NH_MV 
680  m_cSPS.setUpdateRepFormatFlag           ( false );   
681  Bool multiLayerExtensionFlag  = ( getLayerId() > 0 ) && ( m_cVPS->getNumRefLayers( getLayerId() ) > 0 ); 
682 
683  m_cSPS.setSpsExtOrMaxSubLayersMinus1( multiLayerExtensionFlag ? 7 : m_maxTempLayer - 1 );
684  if ( multiLayerExtensionFlag )
685  {
686    m_cSPS.setSpsInferScalingListFlag   ( true ); 
687    m_cSPS.setSpsScalingListRefLayerId( m_cVPS->getIdRefLayer( getLayerId(), 0 ) ); 
688#if NH_MV
689    if ( m_bUseDisparitySearchRangeRestriction )
690    {
691      m_cSPS.setInterViewMvVertConstraintFlag ( true ) ;
692    }
693#endif
694  } 
695  m_cSPS.setSpsExtensionPresentFlag       ( true ); 
696  m_cSPS.setSpsMultilayerExtensionFlag    ( true ); 
697#if NH_3D
698  m_cSPS.setSps3dExtensionFlag            ( true ); 
699#endif
700#endif
701
702  m_cSPS.setPicWidthInLumaSamples  ( m_iSourceWidth      );
703  m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight     );
704  m_cSPS.setConformanceWindow      ( m_conformanceWindow );
705  m_cSPS.setMaxCUWidth             ( m_maxCUWidth        );
706  m_cSPS.setMaxCUHeight            ( m_maxCUHeight       );
707  m_cSPS.setMaxTotalCUDepth        ( m_maxTotalCUDepth   );
708#if NH_3D
709  assert( !getIsDepth()  || m_chromaFormatIDC == CHROMA_400 ); 
710#endif
711  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
712  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize);
713
714  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() );
715  Int log2MinCUSize = 0;
716  while(minCUSize > 1)
717  {
718    minCUSize >>= 1;
719    log2MinCUSize++;
720  }
721
722  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
723
724  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
725  m_cSPS.setUsePCM        ( m_usePCM           );
726  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
727
728  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
729  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
730  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
731  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
732
733  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
734
735  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
736
737  m_cSPS.setUseAMP ( m_useAMP );
738
739  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
740  {
741    m_cSPS.setBitDepth      (ChannelType(channelType), m_bitDepth[channelType] );
742#if O0043_BEST_EFFORT_DECODING
743    m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] );
744#endif
745    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8)));
746    m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType]         );
747  }
748#if NH_MV
749  m_cSPS.inferRepFormat( m_cVPS, getLayerId(), true ); 
750#endif
751m_cSPS.setUseSAO( m_bUseSAO );
752
753  m_cSPS.setMaxTLayers( m_maxTempLayer );
754  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
755
756  for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
757  {
758    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
759    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
760  }
761#if NH_MV
762  for ( Int ols = 0; ols < m_cVPS->getNumOutputLayerSets(); ols++)
763  {
764    // Check MaxDecPicBuffering
765    const std::vector<Int>& targetDecLayerIdList = m_cVPS->getTargetDecLayerIdList( m_cVPS->olsIdxToLsIdx( ols )); 
766    for( Int is = 0; is < targetDecLayerIdList.size(); is++  )
767    {
768      if ( m_cVPS->getNecessaryLayerFlag( ols, is ) )
769      {     
770        m_cSPS.inferSpsMaxDecPicBufferingMinus1( m_cVPS, ols, targetDecLayerIdList[is], true );       
771      }
772    }
773  }
774#endif
775
776
777  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
778  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
779  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
780  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
781
782  if (m_cSPS.getVuiParametersPresentFlag())
783  {
784    TComVUI* pcVUI = m_cSPS.getVuiParameters();
785    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
786    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
787    pcVUI->setSarWidth(getSarWidth());
788    pcVUI->setSarHeight(getSarHeight());
789    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
790    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
791#if NH_MV
792    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 );
793#else
794    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
795#endif
796    pcVUI->setVideoFormat(getVideoFormat());
797    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
798    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
799    pcVUI->setColourPrimaries(getColourPrimaries());
800    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
801    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
802    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
803    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
804    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
805    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
806    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
807    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
808    pcVUI->setFieldSeqFlag(false);
809    pcVUI->setHrdParametersPresentFlag(false);
810    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
811    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
812    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
813    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
814    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
815    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
816    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
817    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
818    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
819    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
820  }
821  m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
822  assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS);
823  for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
824  {
825    m_cSPS.setLtRefPicPocLsbSps(k, 0);
826    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
827  }
828  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
829  {
830    xInitHrdParameters();
831  }
832  if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
833  {
834    m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true );
835  }
836
837  // Set up SPS range extension settings
838  m_cSPS.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag);
839  m_cSPS.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag);
840  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
841  {
842    m_cSPS.getSpsRangeExtension().setRdpcmEnabledFlag(RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]);
843  }
844  m_cSPS.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag);
845  m_cSPS.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag );
846  m_cSPS.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag);
847  m_cSPS.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag);
848  m_cSPS.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag);
849#if NH_MV
850  m_cSPS.setSpsRangeExtensionsFlag( m_cSPS.getSpsRangeExtension().settingsDifferFromDefaults() );
851#endif
852
853}
854
855Void TEncTop::xInitHrdParameters()
856{
857  Bool useSubCpbParams = (getSliceMode() > 0) || (getSliceSegmentMode() > 0);
858  Int  bitRate         = getTargetBitrate();
859  Bool isRandomAccess  = getIntraPeriod() > 0;
860
861  if( !getVuiParametersPresentFlag() )
862  {
863    return;
864  }
865
866  TComVUI *vui = m_cSPS.getVuiParameters();
867  TComHRD *hrd = vui->getHrdParameters();
868
869  TimingInfo *timingInfo = vui->getTimingInfo();
870  timingInfo->setTimingInfoPresentFlag( true );
871  switch( getFrameRate() )
872  {
873  case 24:
874    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
875    break;
876  case 25:
877    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
878    break;
879  case 30:
880    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
881    break;
882  case 50:
883    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
884    break;
885  case 60:
886    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
887    break;
888  default:
889    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
890    break;
891  }
892
893  Bool rateCnt = ( bitRate > 0 );
894  hrd->setNalHrdParametersPresentFlag( rateCnt );
895  hrd->setVclHrdParametersPresentFlag( rateCnt );
896
897  hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams );
898
899  if( hrd->getSubPicCpbParamsPresentFlag() )
900  {
901    hrd->setTickDivisorMinus2( 100 - 2 );                          //
902    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
903    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
904    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
905  }
906  else
907  {
908    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );
909  }
910
911  hrd->setBitRateScale( 4 );                                       // in units of 2^( 6 + 4 ) = 1,024 bps
912  hrd->setCpbSizeScale( 6 );                                       // in units of 2^( 4 + 6 ) = 1,024 bit
913  hrd->setDuCpbSizeScale( 6 );                                     // in units of 2^( 4 + 6 ) = 1,024 bit
914
915  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
916  if( isRandomAccess )
917  {
918    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
919    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
920  }
921  else
922  {
923    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
924    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
925  }
926
927  // Note: parameters for all temporal layers are initialized with the same values
928  Int i, j;
929  UInt bitrateValue, cpbSizeValue;
930  UInt duCpbSizeValue;
931  UInt duBitRateValue = 0;
932
933  for( i = 0; i < MAX_TLAYER; i ++ )
934  {
935    hrd->setFixedPicRateFlag( i, 1 );
936    hrd->setPicDurationInTcMinus1( i, 0 );
937    hrd->setLowDelayHrdFlag( i, 0 );
938    hrd->setCpbCntMinus1( i, 0 );
939
940    //! \todo check for possible PTL violations
941    // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale )
942    bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) );      // bitRate is in bits, so it needs to be scaled down
943    // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale )
944    cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) );      // using bitRate results in 1 second CPB size
945
946    // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know
947    // in how many DUs the slice segment settings will result
948    duCpbSizeValue = bitrateValue;
949    duBitRateValue = cpbSizeValue;
950
951    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
952    {
953      hrd->setBitRateValueMinus1( i, j, 0, ( bitrateValue - 1 ) );
954      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
955      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) );
956      hrd->setDuBitRateValueMinus1( i, j, 0, ( duBitRateValue - 1 ) );
957      hrd->setCbrFlag( i, j, 0, false );
958
959      hrd->setBitRateValueMinus1( i, j, 1, ( bitrateValue - 1) );
960      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
961      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( duCpbSizeValue - 1 ) );
962      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
963      hrd->setCbrFlag( i, j, 1, false );
964    }
965  }
966}
967
968
969Void TEncTop::xInitPPS()
970{
971#if NH_MV
972  m_cPPS.setLayerId( getLayerId() );
973#if NH_3D
974  // Check if this condition is still correct
975  if( getVPS()->getNumRefListLayers( getLayerId() ) > 0 )
976#else
977  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
978#endif
979  {
980    m_cPPS.setListsModificationPresentFlag( true );
981  }
982  m_cPPS.setPPSId( getLayerIdInVps() );
983  m_cPPS.setSPSId( getLayerIdInVps() );
984  m_cPPS.setPpsMultilayerExtensionFlag    ( true ); 
985#if NH_3D
986  // Might be used for DLT
987  m_cPPS.setPps3dExtensionFlag            ( getIsDepth() ); 
988#endif
989#endif
990
991#if NH_3D_DLT
992  // create mapping from depth layer indexes to layer ids
993  Int j=0;
994  for( Int i=0; i<=getVPS()->getMaxLayersMinus1(); i++ )
995  {
996    Int layerId = getVPS()->getLayerIdInNuh(i);
997    if( getVPS()->getDepthId(layerId) )
998      m_cDLT.setDepthIdxToLayerId(j++, layerId);
999  }
1000  m_cPPS.setDLT( m_cDLT );
1001#endif
1002
1003  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1004  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1005
1006  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1007  {
1008    bUseDQP = true;
1009  }
1010
1011  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
1012  {
1013    bUseDQP=false;
1014  }
1015
1016
1017  if ( m_RCEnableRateControl )
1018  {
1019    m_cPPS.setUseDQP(true);
1020    m_cPPS.setMaxCuDQPDepth( 0 );
1021  }
1022  else if(bUseDQP)
1023  {
1024    m_cPPS.setUseDQP(true);
1025    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1026  }
1027  else
1028  {
1029    m_cPPS.setUseDQP(false);
1030    m_cPPS.setMaxCuDQPDepth( 0 );
1031  }
1032
1033  if ( m_diffCuChromaQpOffsetDepth >= 0 )
1034  {
1035    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth);
1036    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1037    m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6);
1038    /* todo, insert table entries from command line (NB, 0 should not be touched) */
1039  }
1040  else
1041  {
1042    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0);
1043    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1044  }
1045  m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag);
1046  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA,   m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA  ]);
1047  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]);
1048
1049  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1050  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
1051
1052  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1053  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1054  m_cPPS.setUseWP( m_useWeightedPred );
1055  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1056  m_cPPS.setOutputFlagPresentFlag( false );
1057#if NH_MV
1058  m_cPPS.setNumExtraSliceHeaderBits( 3 ); 
1059#endif
1060  m_cPPS.setSignHideFlag(getSignHideFlag());
1061  if ( getDeblockingFilterMetric() )
1062  {
1063    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1064    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1065  }
1066  else
1067  {
1068      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1069      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1070    }
1071
1072  if (! m_cPPS.getPicDisableDeblockingFilterFlag())
1073  {
1074    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1075    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
1076  }
1077  else
1078  {
1079    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1080    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1081  }
1082
1083  // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values:
1084  const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() ||
1085                                                  m_cPPS.getPicDisableDeblockingFilterFlag()      ||
1086                                                  m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 ||
1087                                                  m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0;
1088
1089  m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag);
1090
1091  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1092  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1093  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1094
1095
1096  Int histogram[MAX_NUM_REF + 1];
1097  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1098  {
1099    histogram[i]=0;
1100  }
1101  for( Int i = 0; i < getGOPSize(); i++)
1102  {
1103    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1104    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1105  }
1106
1107  Int maxHist=-1;
1108  Int bestPos=0;
1109  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1110  {
1111    if(histogram[i]>maxHist)
1112    {
1113      maxHist=histogram[i];
1114      bestPos=i;
1115    }
1116  }
1117  assert(bestPos <= 15);
1118  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1119  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1120  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1121  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1122  m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize  );
1123
1124  if (m_sliceSegmentMode != NO_SLICES)
1125  {
1126    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1127  }
1128}
1129
1130//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1131Void TEncTop::xInitRPS(Bool isFieldCoding)
1132{
1133  TComReferencePictureSet*      rps;
1134
1135  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
1136  TComRPSList* rpsList = m_cSPS.getRPSList();
1137
1138  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
1139  {
1140    GOPEntry ge = getGOPEntry(i);
1141    rps = rpsList->getReferencePictureSet(i);
1142    rps->setNumberOfPictures(ge.m_numRefPics);
1143    rps->setNumRefIdc(ge.m_numRefIdc);
1144    Int numNeg = 0;
1145    Int numPos = 0;
1146    for( Int j = 0; j < ge.m_numRefPics; j++)
1147    {
1148      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1149      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1150      if(ge.m_referencePics[j]>0)
1151      {
1152        numPos++;
1153      }
1154      else
1155      {
1156        numNeg++;
1157      }
1158    }
1159    rps->setNumberOfNegativePictures(numNeg);
1160    rps->setNumberOfPositivePictures(numPos);
1161
1162    // handle inter RPS intialization from the config file.
1163    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1164    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1165    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
1166
1167    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1168    {
1169      assert (RPSRef!=NULL);
1170      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1171      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1172
1173      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1174      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1175      Int count=0;
1176      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1177      {
1178        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1179        rps->setRefIdc(j, 0);
1180        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1181        {
1182          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1183          {
1184              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1185              count++;
1186              break;
1187          }
1188        }
1189      }
1190      if (count != rps->getNumberOfPictures())
1191      {
1192        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");
1193        rps->setInterRPSPrediction(0);
1194      }
1195    }
1196    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1197    {
1198      assert (RPSRef!=NULL);
1199      rps->setDeltaRPS(ge.m_deltaRPS);
1200      rps->setNumRefIdc(ge.m_numRefIdc);
1201      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1202      {
1203        rps->setRefIdc(j, ge.m_refIdc[j]);
1204      }
1205      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
1206      // computed from the RefIdc.  A warning is printed if they are not identical.
1207      numNeg = 0;
1208      numPos = 0;
1209      TComReferencePictureSet      RPSTemp;  // temporary variable
1210
1211      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1212      {
1213        if (ge.m_refIdc[j])
1214        {
1215          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1216          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1217          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1218          if (deltaPOC<0)
1219          {
1220            numNeg++;
1221          }
1222          else
1223          {
1224            numPos++;
1225          }
1226        }
1227      }
1228      if (numNeg != rps->getNumberOfNegativePictures())
1229      {
1230        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1231        rps->setNumberOfNegativePictures(numNeg);
1232        rps->setNumberOfPictures(numNeg+numPos);
1233      }
1234      if (numPos != rps->getNumberOfPositivePictures())
1235      {
1236        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1237        rps->setNumberOfPositivePictures(numPos);
1238        rps->setNumberOfPictures(numNeg+numPos);
1239      }
1240      RPSTemp.setNumberOfPictures(numNeg+numPos);
1241      RPSTemp.setNumberOfNegativePictures(numNeg);
1242      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1243      // check if Delta POC and Used are the same
1244      // print warning if they are not.
1245      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1246      {
1247        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1248        {
1249          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1250          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1251        }
1252        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1253        {
1254          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1255          rps->setUsed(j,RPSTemp.getUsed(j));
1256        }
1257      }
1258    }
1259  }
1260  //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.
1261  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1262  if (isFieldCoding)
1263  {
1264    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1265    rps->setNumberOfPictures(1);
1266    rps->setNumberOfNegativePictures(1);
1267    rps->setNumberOfPositivePictures(0);
1268    rps->setNumberOfLongtermPictures(0);
1269    rps->setDeltaPOC(0,-1);
1270    rps->setPOC(0,0);
1271    rps->setUsed(0,true);
1272    rps->setInterRPSPrediction(false);
1273    rps->setDeltaRIdxMinus1(0);
1274    rps->setDeltaRPS(0);
1275    rps->setNumRefIdc(0);
1276  }
1277}
1278
1279   // This is a function that
1280   // determines what Reference Picture Set to use
1281   // for a specific slice (with POC = POCCurr)
1282Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1283{
1284#if NH_MV
1285  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
1286  {
1287    TComReferencePictureSet* rps = slice->getLocalRPS();
1288    rps->setNumberOfNegativePictures(0);
1289    rps->setNumberOfPositivePictures(0);
1290    rps->setNumberOfLongtermPictures(0);
1291    rps->setNumberOfPictures(0);
1292    slice->setRPS(rps);
1293  }
1294  else
1295  {
1296#endif
1297  slice->setRPSidx(GOPid);
1298
1299  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1300  {
1301    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1302    {
1303      Int POCIndex = POCCurr%m_uiIntraPeriod;
1304      if(POCIndex == 0)
1305      {
1306        POCIndex = m_uiIntraPeriod;
1307      }
1308      if(POCIndex == m_GOPList[extraNum].m_POC)
1309      {
1310        slice->setRPSidx(extraNum);
1311      }
1312    }
1313    else
1314    {
1315      if(POCCurr==m_GOPList[extraNum].m_POC)
1316      {
1317        slice->setRPSidx(extraNum);
1318      }
1319    }
1320  }
1321
1322  if(POCCurr == 1 && slice->getPic()->isField())
1323  {
1324    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1325  }
1326
1327  const TComReferencePictureSet *rps = (slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1328  slice->setRPS(rps);
1329#if NH_MV
1330  }
1331#endif
1332
1333}
1334
1335Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid )
1336{
1337  Int rpsIdx = GOPid;
1338
1339  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1340  {
1341    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1342    {
1343      Int POCIndex = POCCurr%m_uiIntraPeriod;
1344      if(POCIndex == 0)
1345      {
1346        POCIndex = m_uiIntraPeriod;
1347      }
1348      if(POCIndex == m_GOPList[extraNum].m_POC)
1349      {
1350        rpsIdx = extraNum;
1351      }
1352    }
1353    else
1354    {
1355      if(POCCurr==m_GOPList[extraNum].m_POC)
1356      {
1357        rpsIdx = extraNum;
1358      }
1359    }
1360  }
1361
1362  return rpsIdx;
1363}
1364
1365Void  TEncTop::xInitPPSforTiles()
1366{
1367  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1368  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1369  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1370  if( !m_tileUniformSpacingFlag )
1371  {
1372    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1373    m_cPPS.setTileRowHeight( m_tileRowHeight );
1374  }
1375  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1376
1377  // # substreams is "per tile" when tiles are independent.
1378}
1379
1380Void  TEncCfg::xCheckGSParameters()
1381{
1382  Int   iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth;
1383  Int   iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight;
1384  UInt  uiCummulativeColumnWidth = 0;
1385  UInt  uiCummulativeRowHeight = 0;
1386
1387  //check the column relative parameters
1388  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1389  {
1390    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1391    exit( EXIT_FAILURE );
1392  }
1393
1394  if( m_iNumColumnsMinus1 >= iWidthInCU )
1395  {
1396    printf( "The current picture can not have so many columns.\n" );
1397    exit( EXIT_FAILURE );
1398  }
1399
1400  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1401  {
1402    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1403    {
1404      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1405    }
1406
1407    if( uiCummulativeColumnWidth >= iWidthInCU )
1408    {
1409      printf( "The width of the column is too large.\n" );
1410      exit( EXIT_FAILURE );
1411    }
1412  }
1413
1414  //check the row relative parameters
1415  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1416  {
1417    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1418    exit( EXIT_FAILURE );
1419  }
1420
1421  if( m_iNumRowsMinus1 >= iHeightInCU )
1422  {
1423    printf( "The current picture can not have so many rows.\n" );
1424    exit( EXIT_FAILURE );
1425  }
1426
1427  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1428  {
1429    for(Int i=0; i<m_iNumRowsMinus1; i++)
1430    {
1431      uiCummulativeRowHeight += m_tileRowHeight[i];
1432    }
1433
1434    if( uiCummulativeRowHeight >= iHeightInCU )
1435    {
1436      printf( "The height of the row is too large.\n" );
1437      exit( EXIT_FAILURE );
1438    }
1439  }
1440}
1441
1442#if NH_MV
1443Int TEncTop::getFrameId(Int iGOPid) 
1444{
1445  if(m_iPOCLast == 0)
1446  {
1447    return(0 );
1448  }
1449  else
1450  {
1451    return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ;
1452  }
1453}
1454
1455TComPic* TEncTop::getPic( Int poc )
1456{
1457  TComList<TComPic*>* listPic = getListPic();
1458  TComPic* pcPic = NULL;
1459  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1460  {
1461    if( (*it)->getPOC() == poc )
1462    {
1463      pcPic = *it ;
1464      break ;
1465    }
1466  }
1467  return pcPic;
1468}
1469
1470#endif
1471
1472#if NH_3D_VSO
1473Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset, Int maxCuHeight )
1474{
1475  TRenModel* rendererModel = m_cRdCost.getRenModel(); 
1476  rendererModel->setupPart( iHorOffset, std::min( maxCuHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; 
1477 
1478  Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ];
1479
1480  // setup base views
1481  Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent );
1482
1483  for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ )
1484  {
1485    Int iBaseViewSIdx;
1486    Int iVideoDistMode;
1487    Int iDepthDistMode;
1488
1489    m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode );
1490
1491    AOT( iVideoDistMode < 0 || iVideoDistMode > 2 );
1492
1493    Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ];
1494
1495    TComPicYuv* pcPicYuvVideoRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true  );
1496    TComPicYuv* pcPicYuvDepthRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true  );
1497    TComPicYuv* pcPicYuvVideoOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false );
1498    TComPicYuv* pcPicYuvDepthOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false );   
1499
1500    TComPicYuv* pcPicYuvVideoRef  = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg  : NULL;
1501    TComPicYuv* pcPicYuvDepthRef  = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg  : NULL;
1502
1503    TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg  : pcPicYuvVideoRec;
1504    TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg  : pcPicYuvDepthRec;
1505
1506    AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) );
1507    AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) );
1508    AOT( pcPicYuvDepthTest == NULL );
1509    AOT( pcPicYuvVideoTest == NULL );
1510
1511    rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef );
1512  }
1513
1514  rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 );
1515  // setup virtual views
1516  Int iNumOfSV  = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent );
1517  for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
1518  {
1519    Int iOrgRefBaseViewSIdx;
1520    Int iLeftBaseViewSIdx;
1521    Int iRightBaseViewSIdx;
1522    Int iSynthViewRelNum;
1523    Int iModelNum;
1524    Int iBlendMode;
1525    m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
1526
1527    Int iLeftBaseViewIdx    = -1;
1528    Int iRightBaseViewIdx   = -1;
1529
1530    TComPicYuv* pcPicYuvOrgRef  = NULL;
1531    Int**      ppiShiftLUTLeft  = NULL;
1532    Int**      ppiShiftLUTRight = NULL;
1533    Int**      ppiBaseShiftLUTLeft  = NULL;
1534    Int**      ppiBaseShiftLUTRight = NULL;
1535
1536
1537    Int        iDistToLeft      = -1;
1538
1539    Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum );
1540
1541    if ( iLeftBaseViewSIdx != -1 )
1542    {
1543      iLeftBaseViewIdx   = m_cameraParameters->getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
1544      ppiShiftLUTLeft    = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
1545    }
1546
1547    if ( iRightBaseViewSIdx != -1 )
1548    {
1549      iRightBaseViewIdx  = m_cameraParameters->getBaseSortedId2Id()   [iRightBaseViewSIdx ];
1550      ppiShiftLUTRight   = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
1551    }
1552
1553    if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
1554    {
1555      iDistToLeft          = m_cameraParameters->getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
1556      ppiBaseShiftLUTLeft  = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
1557      ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
1558
1559    }
1560
1561    if ( iOrgRefBaseViewSIdx != -1 )
1562    {
1563      pcPicYuvOrgRef = m_ivPicLists->getPicYuv(  m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false );
1564      AOF ( pcPicYuvOrgRef );
1565    }
1566
1567    rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
1568  }
1569}
1570#endif
1571
1572//! \}
Note: See TracBrowser for help on using the repository browser.