source: 3DVCSoftware/branches/HTM-16.1-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 1399

Last change on this file since 1399 was 1396, checked in by tech, 9 years ago

Merged HTM-16.0-dev1@1395.

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