source: 3DVCSoftware/branches/HTM-14.1-update-dev2-Sharp/source/Lib/TLibEncoder/TEncTop.cpp @ 1225

Last change on this file since 1225 was 1225, checked in by sharpjp-htm, 9 years ago

Migration of illumination compensation(NH_3D_IC) and small fix(H_MV_ENC_DEC_TRAC_FIX)

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