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

Last change on this file since 1417 was 1200, checked in by tech, 10 years ago

Update to HM-16.5.
Starting point for further re-activation of 3D-tools.

Includes:

active:

  • MV-HEVC
  • 3D-HLS (apart from DLT)
  • VSO

inactive:

  • remaining 3D-HEVC tools.
  • Property svn:eol-style set to native
File size: 52.9 KB
RevLine 
[5]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
[1200]4 * granted under this license.
[5]5 *
[1200]6 * Copyright (c) 2010-2015, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
[56]38#include "TLibCommon/CommonDef.h"
[2]39#include "TEncTop.h"
[56]40#include "TEncPic.h"
[1200]41#include "TLibCommon/TComChromaFormat.h"
[56]42#if FAST_BIT_EST
43#include "TLibCommon/ContextModel.h"
44#endif
[1200]45#if NH_MV
[608]46#include "../../App/TAppEncoder/TAppEncTop.h"
47#endif
[2]48
[56]49//! \ingroup TLibEncoder
50//! \{
51
[2]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
[1200]65  if (g_hTrace == NULL)
66  {
67    g_hTrace = fopen( "TraceEnc.txt", "wb" );
68  }
[2]69  g_bJustDoIt = g_bEncDecTraceDisable;
70  g_nSymbolCounter = 0;
71#endif
[56]72
73  m_iMaxRefPicNum     = 0;
74
75#if FAST_BIT_EST
76  ContextModel::buildNextStateTable();
77#endif
[1200]78#if NH_MV
[608]79  m_ivPicLists = NULL;
80#endif
[1084]81#if H_3D_IC
[1066]82  m_aICEnableCandidate = NULL;
83  m_aICEnableNum = NULL;
84#endif
[1200]85#if NH_3D
[1179]86  m_cCavlcCoder.setEncTop(this); 
87#endif
[1200]88
[2]89}
90
91TEncTop::~TEncTop()
92{
93#if ENC_DEC_TRACE
[1200]94  if (g_hTrace != stdout)
95  {
96    fclose( g_hTrace );
97  }
[2]98#endif
99}
100
101Void TEncTop::create ()
102{
[1200]103#if !NH_MV
[2]104  // initialize global variables
[608]105  initROM();
106#endif
[1200]107
[2]108  // create processing unit classes
[1200]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 );
[2]112  if (m_bUseSAO)
113  {
[1200]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());
[2]116  }
[56]117#if ADAPTIVE_QP_SELECTION
118  if (m_bUseAdaptQpSelect)
119  {
120    m_cTrQuant.initSliceQpDelta();
121  }
[2]122#endif
123
[1200]124  m_cLoopFilter.create( m_maxTotalCUDepth );
125
[608]126  if ( m_RCEnableRateControl )
[2]127  {
[655]128#if KWU_RC_MADPRED_E0227
[608]129    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
[655]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,
[1200]133        m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
[655]134#endif
[2]135  }
[1200]136
137  m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1];
[56]138#if FAST_BIT_EST
[1200]139  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1];
[56]140#else
[1200]141  m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1];
[56]142#endif
[1200]143
144  for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
145  {
146    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
[56]147#if FAST_BIT_EST
[1200]148    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
[56]149#else
[1200]150    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
[56]151#endif
[1200]152
153    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
154    {
155      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
[56]156#if FAST_BIT_EST
[1200]157      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
[56]158#else
[1200]159      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
[56]160#endif
[1200]161      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
[2]162    }
163  }
[1200]164}
[2]165
166Void TEncTop::destroy ()
167{
168  // destroy processing unit classes
[56]169  m_cGOPEncoder.        destroy();
[2]170  m_cSliceEncoder.      destroy();
171  m_cCuEncoder.         destroy();
[1200]172  m_cEncSAO.            destroyEncData();
173  m_cEncSAO.            destroy();
[2]174  m_cLoopFilter.        destroy();
[608]175  m_cRateCtrl.          destroy();
[1200]176  Int iDepth;
177  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
178  {
179    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
[2]180    {
[1200]181      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
182      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
[2]183    }
[1200]184  }
[1066]185
[1200]186  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
187  {
188    delete [] m_pppcRDSbacCoder[iDepth];
189    delete [] m_pppcBinCoderCABAC[iDepth];
190  }
[56]191
[1200]192  delete [] m_pppcRDSbacCoder;
193  delete [] m_pppcBinCoderCABAC;
[1066]194
[1200]195#if !NH_MV
196  // destroy ROM
[56]197  destroyROM();
[608]198#endif
199
[2]200  return;
201}
202
[655]203#if KWU_RC_MADPRED_E0227
204Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding)
205#else
206Void TEncTop::init(Bool isFieldCoding)
207#endif
[2]208{
209  // initialize SPS
[773]210#if H_3D
[758]211  // Assuming that all PPS indirectly refer to the same VPS via different SPS
212  m_cSPS.setVPS(m_cVPS);
213#endif
[2]214  xInitSPS();
[1200]215  xInitVPS();
216
217  m_cRdCost.setCostMode(m_costMode);
218
219#if NH_MV
[608]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
[2]224  // initialize PPS
225  xInitPPS();
[655]226  xInitRPS(isFieldCoding);
[2]227
[56]228  xInitPPSforTiles();
[1084]229#if H_3D_IC
[1066]230  m_aICEnableCandidate = new Int[ 10 ];
231  m_aICEnableNum = new Int[ 10 ];
[56]232
[1066]233  for(int i=0;i<10;i++)
234  {
235    m_aICEnableCandidate[i]=0;
236    m_aICEnableNum[i]=0;
237  }
238#endif
[1179]239
[2]240  // initialize processing unit classes
[56]241  m_cGOPEncoder.  init( this );
[2]242  m_cSliceEncoder.init( this );
243  m_cCuEncoder.   init( this );
[1200]244
[655]245#if KWU_RC_MADPRED_E0227
246  m_pcTAppEncTop = pcTAppEncTop;
247#endif
[2]248  // initialize transform & quantization class
249  m_pcCavlcCoder = getCavlcCoder();
[1200]250
[608]251  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
[1200]252                   m_useRDOQ,
253                   m_useRDOQTS,
254#if T0196_SELECTIVE_RDOQ
255                   m_useSelectiveRDOQ,
256#endif
257                   true
[608]258                  ,m_useTransformSkipFast
[1200]259#if ADAPTIVE_QP_SELECTION
260                  ,m_bUseAdaptQpSelect
[2]261#endif
[56]262                  );
[1200]263
[2]264  // initialize encoder search class
[1200]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() );
[56]266
267  m_iMaxRefPicNum = 0;
[1200]268
269  xInitScalingLists();
[2]270}
271
[1200]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
[2]333// ====================================================================================================================
334// Public member functions
335// ====================================================================================================================
336
[1200]337#if NH_MV
[608]338Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg )
[56]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  }
[1200]351#if NH_MV
[608]352  pcPicCurr->setLayerId( getLayerId()); 
353#endif
[1200]354#if NH_3D
[1179]355  pcPicCurr->setScaleOffset( m_cameraParameters->getCodedScale(), m_cameraParameters->getCodedOffset() );
[608]356#endif
[56]357}
[608]358#endif
[1200]359
[2]360Void TEncTop::deletePicBuffer()
361{
362  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
363  Int iSize = Int( m_cListPic.size() );
[1200]364
[2]365  for ( Int i = 0; i < iSize; i++ )
366  {
367    TComPic* pcPic = *(iterPic++);
[1200]368
[2]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 .
[608]380 \param   flush               cause encoder to encode a partial GOP
[2]381 \param   pcPicYuvOrg         original YUV picture
[1200]382 \param   pcPicYuvTrueOrg     
383 \param   snrCSC
[2]384 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
[1200]385 \retval  accessUnitsOut      list of output access units
[2]386 \retval  iNumEncoded         number of encoded pictures
387 */
[1200]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 )
[608]390{
391#else
[1200]392Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
[608]393{
394#endif
[1200]395#if NH_3D
[608]396  TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() );
397  if( picLastCoded )
398  {
399    picLastCoded->compressMotion(1); 
400  }
401#endif
[1200]402#if NH_MV
[56]403  if( gopId == 0)
[2]404  {
[56]405    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); 
[608]406#else
[1200]407  if (pcPicYuvOrg != NULL)
408  {
[608]409    // get original YUV
410    TComPic* pcPicCurr = NULL;
[1200]411
[608]412    xGetNewPicBuffer( pcPicCurr );
413    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
[1200]414    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
[608]415
416    // compute image characteristics
417    if ( getUseAdaptiveQP() )
418    {
419      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
420    }
[2]421  }
[1200]422
423  if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0)))
[2]424  {
[608]425    iNumEncoded = 0;
426    return;
[2]427  }
[608]428#endif
429  if ( m_RCEnableRateControl )
[2]430  {
[608]431    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
[2]432  }
[1200]433#if NH_MV
[608]434  }
[1200]435  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE, gopId);
[2]436
[608]437  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
[2]438  {
[608]439#else
440  // compress GOP
[1200]441  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
[5]442#endif
[608]443  if ( m_RCEnableRateControl )
[2]444  {
[608]445    m_cRateCtrl.destroyRCGOP();
[2]446  }
[1200]447
[608]448  iNumEncoded         = m_iNumPicRcvd;
449  m_iNumPicRcvd       = 0;
450  m_uiNumAllPicCoded += iNumEncoded;
[1200]451#if NH_MV
[2]452}
[608]453#endif
454}
[1200]455
[655]456/**------------------------------------------------
457 Separate interlaced frame into two fields
458 -------------------------------------------------**/
[1200]459Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
[655]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    }
[1200]471
[655]472    dstField += stride;
473    org += stride*2;
474  }
[1200]475
[655]476}
[1200]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 )
[655]479{
[1124]480  assert( 0 ); // Field coding and multiview need to be further harmonized.
[655]481}
482#else
[1200]483Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
[655]484{
[1200]485  iNumEncoded = 0;
486
487  for (Int fieldNum=0; fieldNum<2; fieldNum++)
[655]488  {
[1200]489    if (pcPicYuvOrg)
[872]490    {
[1200]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      }
[655]546    }
[1200]547
548    if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
[655]549    {
[1200]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;
[655]556    }
557  }
558}
559#endif
[2]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{
[1200]573  // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
574
[2]575  TComSlice::sortPicList(m_cListPic);
[1200]576
577
[56]578  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
[2]579  {
[56]580    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
581    Int iSize = Int( m_cListPic.size() );
582    for ( Int i = 0; i < iSize; i++ )
583    {
[608]584      rpcPic = *(iterPic++);
[56]585      if(rpcPic->getSlice(0)->isReferenced() == false)
[608]586      {
587        break;
588      }
[56]589    }
[2]590  }
591  else
592  {
[608]593    if ( getUseAdaptiveQP() )
594    {
595      TEncPic* pcEPic = new TEncPic;
[1200]596      pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false);
[608]597      rpcPic = pcEPic;
598    }
599    else
600    {
601      rpcPic = new TComPic;
[1200]602      rpcPic->create( m_cSPS, m_cPPS, false );
603    }
[608]604
[56]605    m_cListPic.pushBack( rpcPic );
[2]606  }
607  rpcPic->setReconMark (false);
[1200]608
[2]609  m_iPOCLast++;
610  m_iNumPicRcvd++;
[1200]611
[2]612  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
613  // mark it should be extended
614  rpcPic->getPicYuvRec()->setBorderExtension(false);
[1200]615#if NH_MV
[608]616  rpcPic->getPicYuvOrg()->setBorderExtension(false);
[622]617#endif
[1200]618
[2]619}
620
[1200]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
[2]643Void TEncTop::xInitSPS()
644{
[1200]645#if NH_MV
[608]646  m_cSPS.setSPSId( getLayerIdInVps() );
647  m_cSPS.setLayerId( getLayerId() );
[872]648 // Code below needs to be moved to VPS
649#endif
[608]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);
[1200]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))
[608]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 */
[1200]678#if NH_MV 
[738]679  m_cSPS.setUpdateRepFormatFlag           ( false );   
[1066]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 ) ); 
[1200]687#if NH_MV
[1179]688    if ( m_bUseDisparitySearchRangeRestriction )
689    {
690      m_cSPS.setInterViewMvVertConstraintFlag ( true ) ;
691    }
692#endif
693  } 
[1066]694  m_cSPS.setSpsExtensionPresentFlag       ( true ); 
[964]695  m_cSPS.setSpsMultilayerExtensionFlag    ( true ); 
[1200]696#if NH_3D
[964]697  m_cSPS.setSps3dExtensionFlag            ( true ); 
[622]698#endif
[738]699#endif
[1200]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 ); 
[1179]709#endif
[1200]710  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
711  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize);
[608]712
[1200]713  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() );
[608]714  Int log2MinCUSize = 0;
715  while(minCUSize > 1)
716  {
717    minCUSize >>= 1;
718    log2MinCUSize++;
719  }
720
721  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
[1200]722
[56]723  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
724  m_cSPS.setUsePCM        ( m_usePCM           );
725  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
[2]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    );
[608]731
[1200]732  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
733
[56]734  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
[2]735
[56]736  m_cSPS.setUseAMP ( m_useAMP );
[2]737
[1200]738  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
[56]739  {
[1200]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]         );
[56]746  }
[1200]747#if NH_MV
748  m_cSPS.inferRepFormat( m_cVPS, getLayerId(), true ); 
749#endif
750m_cSPS.setUseSAO( m_bUseSAO );
[56]751
752  m_cSPS.setMaxTLayers( m_maxTempLayer );
[608]753  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
[1200]754
755  for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
[56]756  {
757    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
758    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
759  }
[1200]760#if NH_MV
[964]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    {
[1066]767      if ( m_cVPS->getNecessaryLayerFlag( ols, is ) )
768      {     
769        m_cSPS.inferSpsMaxDecPicBufferingMinus1( m_cVPS, ols, targetDecLayerIdList[is], true );       
770      }
[964]771    }
772  }
773#endif
[42]774
[56]775
[1200]776  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
777  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
[608]778  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
[1200]779  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
[210]780
[608]781  if (m_cSPS.getVuiParametersPresentFlag())
[56]782  {
[608]783    TComVUI* pcVUI = m_cSPS.getVuiParameters();
[1084]784    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
[608]785    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
786    pcVUI->setSarWidth(getSarWidth());
787    pcVUI->setSarHeight(getSarHeight());
788    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
789    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
[1200]790#if NH_MV
[738]791    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 );
792#else
[1200]793    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
[738]794#endif
[608]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());
[2]819  }
[1200]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
[56]852}
[2]853
[1200]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
[56]967Void TEncTop::xInitPPS()
968{
[1200]969#if NH_MV
[622]970  m_cPPS.setLayerId( getLayerId() );
[1200]971#if NH_3D
[1124]972  // Check if this condition is still correct
973  if( getVPS()->getNumRefListLayers( getLayerId() ) > 0 )
974#else
[622]975  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
[1124]976#endif
[608]977  {
978    m_cPPS.setListsModificationPresentFlag( true );
979  }
980  m_cPPS.setPPSId( getLayerIdInVps() );
981  m_cPPS.setSPSId( getLayerIdInVps() );
[964]982  m_cPPS.setPpsMultilayerExtensionFlag    ( true ); 
[1200]983#if NH_3D
984  // Might be used for DLT
985  m_cPPS.setPps3dExtensionFlag            ( getIsDepth() ); 
[964]986#endif
[608]987#endif
[758]988
[773]989#if H_3D
[758]990  m_cPPS.setDLT( getDLT() );
991#endif
[1200]992
[56]993  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
994  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
[2]995
[1200]996  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
997  {
998    bUseDQP = true;
999  }
[56]1000
[1200]1001  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
[56]1002  {
[1200]1003    bUseDQP=false;
1004  }
1005
1006
1007  if ( m_RCEnableRateControl )
1008  {
[56]1009    m_cPPS.setUseDQP(true);
[1200]1010    m_cPPS.setMaxCuDQPDepth( 0 );
1011  }
1012  else if(bUseDQP)
1013  {
1014    m_cPPS.setUseDQP(true);
[56]1015    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1016  }
1017  else
1018  {
1019    m_cPPS.setUseDQP(false);
1020    m_cPPS.setMaxCuDQPDepth( 0 );
1021  }
[2]1022
[1200]1023  if ( m_diffCuChromaQpOffsetDepth >= 0 )
[608]1024  {
[1200]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) */
[655]1029  }
[1200]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]);
[2]1038
[1200]1039  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1040  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
[608]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 );
[56]1046  m_cPPS.setOutputFlagPresentFlag( false );
[1200]1047#if NH_MV
[738]1048  m_cPPS.setNumExtraSliceHeaderBits( 3 ); 
[608]1049#endif
[56]1050  m_cPPS.setSignHideFlag(getSignHideFlag());
[655]1051  if ( getDeblockingFilterMetric() )
1052  {
1053    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1054    m_cPPS.setPicDisableDeblockingFilterFlag(false);
[1200]1055  }
[655]1056  else
1057  {
[1200]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() );
[655]1066  }
[1200]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
[608]1081  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
[56]1082  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
[608]1083  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
[1200]1084
1085
[608]1086  Int histogram[MAX_NUM_REF + 1];
1087  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1088  {
1089    histogram[i]=0;
1090  }
[1200]1091  for( Int i = 0; i < getGOPSize(); i++)
[608]1092  {
1093    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1094    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1095  }
[1200]1096
[608]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 );
[1200]1112  m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize  );
1113
1114  if (m_sliceSegmentMode != NO_SLICES)
[608]1115  {
1116    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1117  }
[2]1118}
1119
[56]1120//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
[655]1121Void TEncTop::xInitRPS(Bool isFieldCoding)
[2]1122{
[56]1123  TComReferencePictureSet*      rps;
[1200]1124
1125  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
[608]1126  TComRPSList* rpsList = m_cSPS.getRPSList();
1127
[1200]1128  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
[56]1129  {
[608]1130    GOPEntry ge = getGOPEntry(i);
1131    rps = rpsList->getReferencePictureSet(i);
[56]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++)
[2]1137    {
[56]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      }
[2]1148    }
[56]1149    rps->setNumberOfNegativePictures(numNeg);
1150    rps->setNumberOfPositivePictures(numPos);
[608]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.
[1200]1155    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
[608]1156
1157    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1158    {
[1200]1159      assert (RPSRef!=NULL);
[608]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        {
[1200]1172          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
[608]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    {
[1200]1188      assert (RPSRef!=NULL);
[608]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      }
[1200]1195      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
[608]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);
[655]1222        rps->setNumberOfPictures(numNeg+numPos);
[608]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);
[655]1228        rps->setNumberOfPictures(numNeg+numPos);
[608]1229      }
1230      RPSTemp.setNumberOfPictures(numNeg+numPos);
1231      RPSTemp.setNumberOfNegativePictures(numNeg);
1232      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
[1200]1233      // check if Delta POC and Used are the same
[608]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    }
[56]1249  }
[1200]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)
[655]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);
[1200]1266  }
[56]1267}
[2]1268
[1200]1269   // This is a function that
1270   // determines what Reference Picture Set to use
[56]1271   // for a specific slice (with POC = POCCurr)
[608]1272Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
[56]1273{
[1200]1274#if NH_MV
[608]1275  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
[56]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  {
[608]1286#endif
1287  slice->setRPSidx(GOPid);
[2]1288
[608]1289  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
[1200]1290  {
[608]1291    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1292    {
1293      Int POCIndex = POCCurr%m_uiIntraPeriod;
1294      if(POCIndex == 0)
[56]1295      {
[608]1296        POCIndex = m_uiIntraPeriod;
[56]1297      }
[608]1298      if(POCIndex == m_GOPList[extraNum].m_POC)
[56]1299      {
[608]1300        slice->setRPSidx(extraNum);
[56]1301      }
1302    }
[608]1303    else
1304    {
1305      if(POCCurr==m_GOPList[extraNum].m_POC)
1306      {
1307        slice->setRPSidx(extraNum);
1308      }
1309    }
1310  }
[1200]1311
[655]1312  if(POCCurr == 1 && slice->getPic()->isField())
1313  {
1314    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1315  }
[2]1316
[1200]1317  TComReferencePictureSet *rps=slice->getLocalRPS();
1318  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1319  slice->setRPS(rps);
[608]1320  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
[1200]1321#if NH_MV
[56]1322  }
[608]1323#endif
1324
[2]1325}
1326
[1200]1327Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid )
[2]1328{
[1200]1329  Int rpsIdx = GOPid;
[2]1330
[608]1331  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
[1200]1332  {
[608]1333    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
[2]1334    {
[608]1335      Int POCIndex = POCCurr%m_uiIntraPeriod;
1336      if(POCIndex == 0)
[2]1337      {
[608]1338        POCIndex = m_uiIntraPeriod;
[2]1339      }
[608]1340      if(POCIndex == m_GOPList[extraNum].m_POC)
[2]1341      {
[608]1342        rpsIdx = extraNum;
[2]1343      }
1344    }
[608]1345    else
[56]1346    {
[608]1347      if(POCCurr==m_GOPList[extraNum].m_POC)
[56]1348      {
[608]1349        rpsIdx = extraNum;
[56]1350      }
1351    }
[2]1352  }
[56]1353
[608]1354  return rpsIdx;
[56]1355}
1356
1357Void  TEncTop::xInitPPSforTiles()
1358{
[1084]1359  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1360  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1361  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1362  if( !m_tileUniformSpacingFlag )
[608]1363  {
[1084]1364    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1365    m_cPPS.setTileRowHeight( m_tileRowHeight );
[608]1366  }
1367  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
[56]1368
[608]1369  // # substreams is "per tile" when tiles are independent.
[2]1370}
1371
[56]1372Void  TEncCfg::xCheckGSParameters()
[2]1373{
[1200]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;
[56]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)) )
[2]1381  {
[56]1382    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1383    exit( EXIT_FAILURE );
[2]1384  }
[56]1385
1386  if( m_iNumColumnsMinus1 >= iWidthInCU )
[2]1387  {
[56]1388    printf( "The current picture can not have so many columns.\n" );
1389    exit( EXIT_FAILURE );
[2]1390  }
[56]1391
[1084]1392  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
[2]1393  {
[56]1394    for(Int i=0; i<m_iNumColumnsMinus1; i++)
[608]1395    {
[1084]1396      uiCummulativeColumnWidth += m_tileColumnWidth[i];
[608]1397    }
[56]1398
1399    if( uiCummulativeColumnWidth >= iWidthInCU )
1400    {
1401      printf( "The width of the column is too large.\n" );
1402      exit( EXIT_FAILURE );
1403    }
[2]1404  }
[56]1405
1406  //check the row relative parameters
1407  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
[2]1408  {
[56]1409    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1410    exit( EXIT_FAILURE );
[2]1411  }
[56]1412
1413  if( m_iNumRowsMinus1 >= iHeightInCU )
[2]1414  {
[56]1415    printf( "The current picture can not have so many rows.\n" );
1416    exit( EXIT_FAILURE );
[2]1417  }
1418
[1084]1419  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
[56]1420  {
1421    for(Int i=0; i<m_iNumRowsMinus1; i++)
[1200]1422    {
[1084]1423      uiCummulativeRowHeight += m_tileRowHeight[i];
[1200]1424    }
[56]1425
1426    if( uiCummulativeRowHeight >= iHeightInCU )
1427    {
1428      printf( "The height of the row is too large.\n" );
1429      exit( EXIT_FAILURE );
1430    }
1431  }
[2]1432}
1433
[1200]1434#if NH_MV
[608]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}
[1200]1461
[608]1462#endif
1463
[1200]1464#if NH_3D_VSO
1465Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset, Int maxCuHeight )
[608]1466{
1467  TRenModel* rendererModel = m_cRdCost.getRenModel(); 
[1200]1468  rendererModel->setupPart( iHorOffset, std::min( maxCuHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; 
[608]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
[1200]1563
[56]1564//! \}
Note: See TracBrowser for help on using the repository browser.