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

Last change on this file since 1417 was 1251, checked in by rwth, 10 years ago
  • bug fix
  • Property svn:eol-style set to native
File size: 53.2 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
[1219]989#if NH_3D_DLT
990  // create mapping from depth layer indexes to layer ids
991  Int j=0;
992  for( Int i=0; i<=getVPS()->getMaxLayersMinus1(); i++ )
993  {
994    Int layerId = getVPS()->getLayerIdInNuh(i);
995    if( getVPS()->getDepthId(layerId) )
[1251]996      m_cDLT.setDepthIdxToLayerId(j++, layerId);
[1219]997  }
998  m_cPPS.setDLT( m_cDLT );
[758]999#endif
[1200]1000
[56]1001  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1002  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
[2]1003
[1200]1004  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1005  {
1006    bUseDQP = true;
1007  }
[56]1008
[1200]1009  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
[56]1010  {
[1200]1011    bUseDQP=false;
1012  }
1013
1014
1015  if ( m_RCEnableRateControl )
1016  {
[56]1017    m_cPPS.setUseDQP(true);
[1200]1018    m_cPPS.setMaxCuDQPDepth( 0 );
1019  }
1020  else if(bUseDQP)
1021  {
1022    m_cPPS.setUseDQP(true);
[56]1023    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1024  }
1025  else
1026  {
1027    m_cPPS.setUseDQP(false);
1028    m_cPPS.setMaxCuDQPDepth( 0 );
1029  }
[2]1030
[1200]1031  if ( m_diffCuChromaQpOffsetDepth >= 0 )
[608]1032  {
[1200]1033    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth);
1034    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1035    m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6);
1036    /* todo, insert table entries from command line (NB, 0 should not be touched) */
[655]1037  }
[1200]1038  else
1039  {
1040    m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0);
1041    m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList();
1042  }
1043  m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag);
1044  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA,   m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA  ]);
1045  m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]);
[2]1046
[1200]1047  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1048  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
[608]1049
1050  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1051  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1052  m_cPPS.setUseWP( m_useWeightedPred );
1053  m_cPPS.setWPBiPred( m_useWeightedBiPred );
[56]1054  m_cPPS.setOutputFlagPresentFlag( false );
[1200]1055#if NH_MV
[738]1056  m_cPPS.setNumExtraSliceHeaderBits( 3 ); 
[608]1057#endif
[56]1058  m_cPPS.setSignHideFlag(getSignHideFlag());
[655]1059  if ( getDeblockingFilterMetric() )
1060  {
1061    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1062    m_cPPS.setPicDisableDeblockingFilterFlag(false);
[1200]1063  }
[655]1064  else
1065  {
[1200]1066      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1067      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1068    }
1069
1070  if (! m_cPPS.getPicDisableDeblockingFilterFlag())
1071  {
1072    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1073    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
[655]1074  }
[1200]1075  else
1076  {
1077    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1078    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1079  }
1080
1081  // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values:
1082  const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() ||
1083                                                  m_cPPS.getPicDisableDeblockingFilterFlag()      ||
1084                                                  m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 ||
1085                                                  m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0;
1086
1087  m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag);
1088
[608]1089  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
[56]1090  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
[608]1091  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
[1200]1092
1093
[608]1094  Int histogram[MAX_NUM_REF + 1];
1095  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1096  {
1097    histogram[i]=0;
1098  }
[1200]1099  for( Int i = 0; i < getGOPSize(); i++)
[608]1100  {
1101    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1102    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1103  }
[1200]1104
[608]1105  Int maxHist=-1;
1106  Int bestPos=0;
1107  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1108  {
1109    if(histogram[i]>maxHist)
1110    {
1111      maxHist=histogram[i];
1112      bestPos=i;
1113    }
1114  }
1115  assert(bestPos <= 15);
1116  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1117  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1118  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1119  m_cPPS.setUseTransformSkip( m_useTransformSkip );
[1200]1120  m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize  );
1121
1122  if (m_sliceSegmentMode != NO_SLICES)
[608]1123  {
1124    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1125  }
[2]1126}
1127
[56]1128//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
[655]1129Void TEncTop::xInitRPS(Bool isFieldCoding)
[2]1130{
[56]1131  TComReferencePictureSet*      rps;
[1200]1132
1133  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
[608]1134  TComRPSList* rpsList = m_cSPS.getRPSList();
1135
[1200]1136  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
[56]1137  {
[608]1138    GOPEntry ge = getGOPEntry(i);
1139    rps = rpsList->getReferencePictureSet(i);
[56]1140    rps->setNumberOfPictures(ge.m_numRefPics);
1141    rps->setNumRefIdc(ge.m_numRefIdc);
1142    Int numNeg = 0;
1143    Int numPos = 0;
1144    for( Int j = 0; j < ge.m_numRefPics; j++)
[2]1145    {
[56]1146      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1147      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1148      if(ge.m_referencePics[j]>0)
1149      {
1150        numPos++;
1151      }
1152      else
1153      {
1154        numNeg++;
1155      }
[2]1156    }
[56]1157    rps->setNumberOfNegativePictures(numNeg);
1158    rps->setNumberOfPositivePictures(numPos);
[608]1159
1160    // handle inter RPS intialization from the config file.
1161    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1162    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
[1200]1163    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
[608]1164
1165    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1166    {
[1200]1167      assert (RPSRef!=NULL);
[608]1168      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1169      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1170
1171      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1172      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1173      Int count=0;
1174      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1175      {
1176        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1177        rps->setRefIdc(j, 0);
1178        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1179        {
[1200]1180          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
[608]1181          {
1182              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1183              count++;
1184              break;
1185          }
1186        }
1187      }
1188      if (count != rps->getNumberOfPictures())
1189      {
1190        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");
1191        rps->setInterRPSPrediction(0);
1192      }
1193    }
1194    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1195    {
[1200]1196      assert (RPSRef!=NULL);
[608]1197      rps->setDeltaRPS(ge.m_deltaRPS);
1198      rps->setNumRefIdc(ge.m_numRefIdc);
1199      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1200      {
1201        rps->setRefIdc(j, ge.m_refIdc[j]);
1202      }
[1200]1203      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
[608]1204      // computed from the RefIdc.  A warning is printed if they are not identical.
1205      numNeg = 0;
1206      numPos = 0;
1207      TComReferencePictureSet      RPSTemp;  // temporary variable
1208
1209      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1210      {
1211        if (ge.m_refIdc[j])
1212        {
1213          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1214          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1215          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1216          if (deltaPOC<0)
1217          {
1218            numNeg++;
1219          }
1220          else
1221          {
1222            numPos++;
1223          }
1224        }
1225      }
1226      if (numNeg != rps->getNumberOfNegativePictures())
1227      {
1228        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1229        rps->setNumberOfNegativePictures(numNeg);
[655]1230        rps->setNumberOfPictures(numNeg+numPos);
[608]1231      }
1232      if (numPos != rps->getNumberOfPositivePictures())
1233      {
1234        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1235        rps->setNumberOfPositivePictures(numPos);
[655]1236        rps->setNumberOfPictures(numNeg+numPos);
[608]1237      }
1238      RPSTemp.setNumberOfPictures(numNeg+numPos);
1239      RPSTemp.setNumberOfNegativePictures(numNeg);
1240      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
[1200]1241      // check if Delta POC and Used are the same
[608]1242      // print warning if they are not.
1243      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1244      {
1245        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1246        {
1247          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1248          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1249        }
1250        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1251        {
1252          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1253          rps->setUsed(j,RPSTemp.getUsed(j));
1254        }
1255      }
1256    }
[56]1257  }
[1200]1258  //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.
1259  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1260  if (isFieldCoding)
[655]1261  {
1262    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1263    rps->setNumberOfPictures(1);
1264    rps->setNumberOfNegativePictures(1);
1265    rps->setNumberOfPositivePictures(0);
1266    rps->setNumberOfLongtermPictures(0);
1267    rps->setDeltaPOC(0,-1);
1268    rps->setPOC(0,0);
1269    rps->setUsed(0,true);
1270    rps->setInterRPSPrediction(false);
1271    rps->setDeltaRIdxMinus1(0);
1272    rps->setDeltaRPS(0);
1273    rps->setNumRefIdc(0);
[1200]1274  }
[56]1275}
[2]1276
[1200]1277   // This is a function that
1278   // determines what Reference Picture Set to use
[56]1279   // for a specific slice (with POC = POCCurr)
[608]1280Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
[56]1281{
[1200]1282#if NH_MV
[608]1283  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
[56]1284  {
1285    TComReferencePictureSet* rps = slice->getLocalRPS();
1286    rps->setNumberOfNegativePictures(0);
1287    rps->setNumberOfPositivePictures(0);
1288    rps->setNumberOfLongtermPictures(0);
1289    rps->setNumberOfPictures(0);
1290    slice->setRPS(rps);
1291  }
1292  else
1293  {
[608]1294#endif
1295  slice->setRPSidx(GOPid);
[2]1296
[608]1297  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
[1200]1298  {
[608]1299    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1300    {
1301      Int POCIndex = POCCurr%m_uiIntraPeriod;
1302      if(POCIndex == 0)
[56]1303      {
[608]1304        POCIndex = m_uiIntraPeriod;
[56]1305      }
[608]1306      if(POCIndex == m_GOPList[extraNum].m_POC)
[56]1307      {
[608]1308        slice->setRPSidx(extraNum);
[56]1309      }
1310    }
[608]1311    else
1312    {
1313      if(POCCurr==m_GOPList[extraNum].m_POC)
1314      {
1315        slice->setRPSidx(extraNum);
1316      }
1317    }
1318  }
[1200]1319
[655]1320  if(POCCurr == 1 && slice->getPic()->isField())
1321  {
1322    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1323  }
[2]1324
[1200]1325  TComReferencePictureSet *rps=slice->getLocalRPS();
1326  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1327  slice->setRPS(rps);
[608]1328  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
[1200]1329#if NH_MV
[56]1330  }
[608]1331#endif
1332
[2]1333}
1334
[1200]1335Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid )
[2]1336{
[1200]1337  Int rpsIdx = GOPid;
[2]1338
[608]1339  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
[1200]1340  {
[608]1341    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
[2]1342    {
[608]1343      Int POCIndex = POCCurr%m_uiIntraPeriod;
1344      if(POCIndex == 0)
[2]1345      {
[608]1346        POCIndex = m_uiIntraPeriod;
[2]1347      }
[608]1348      if(POCIndex == m_GOPList[extraNum].m_POC)
[2]1349      {
[608]1350        rpsIdx = extraNum;
[2]1351      }
1352    }
[608]1353    else
[56]1354    {
[608]1355      if(POCCurr==m_GOPList[extraNum].m_POC)
[56]1356      {
[608]1357        rpsIdx = extraNum;
[56]1358      }
1359    }
[2]1360  }
[56]1361
[608]1362  return rpsIdx;
[56]1363}
1364
1365Void  TEncTop::xInitPPSforTiles()
1366{
[1084]1367  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1368  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1369  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1370  if( !m_tileUniformSpacingFlag )
[608]1371  {
[1084]1372    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1373    m_cPPS.setTileRowHeight( m_tileRowHeight );
[608]1374  }
1375  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
[56]1376
[608]1377  // # substreams is "per tile" when tiles are independent.
[2]1378}
1379
[56]1380Void  TEncCfg::xCheckGSParameters()
[2]1381{
[1200]1382  Int   iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth;
1383  Int   iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight;
[56]1384  UInt  uiCummulativeColumnWidth = 0;
1385  UInt  uiCummulativeRowHeight = 0;
1386
1387  //check the column relative parameters
1388  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
[2]1389  {
[56]1390    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1391    exit( EXIT_FAILURE );
[2]1392  }
[56]1393
1394  if( m_iNumColumnsMinus1 >= iWidthInCU )
[2]1395  {
[56]1396    printf( "The current picture can not have so many columns.\n" );
1397    exit( EXIT_FAILURE );
[2]1398  }
[56]1399
[1084]1400  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
[2]1401  {
[56]1402    for(Int i=0; i<m_iNumColumnsMinus1; i++)
[608]1403    {
[1084]1404      uiCummulativeColumnWidth += m_tileColumnWidth[i];
[608]1405    }
[56]1406
1407    if( uiCummulativeColumnWidth >= iWidthInCU )
1408    {
1409      printf( "The width of the column is too large.\n" );
1410      exit( EXIT_FAILURE );
1411    }
[2]1412  }
[56]1413
1414  //check the row relative parameters
1415  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
[2]1416  {
[56]1417    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1418    exit( EXIT_FAILURE );
[2]1419  }
[56]1420
1421  if( m_iNumRowsMinus1 >= iHeightInCU )
[2]1422  {
[56]1423    printf( "The current picture can not have so many rows.\n" );
1424    exit( EXIT_FAILURE );
[2]1425  }
1426
[1084]1427  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
[56]1428  {
1429    for(Int i=0; i<m_iNumRowsMinus1; i++)
[1200]1430    {
[1084]1431      uiCummulativeRowHeight += m_tileRowHeight[i];
[1200]1432    }
[56]1433
1434    if( uiCummulativeRowHeight >= iHeightInCU )
1435    {
1436      printf( "The height of the row is too large.\n" );
1437      exit( EXIT_FAILURE );
1438    }
1439  }
[2]1440}
1441
[1200]1442#if NH_MV
[608]1443Int TEncTop::getFrameId(Int iGOPid) 
1444{
1445  if(m_iPOCLast == 0)
1446  {
1447    return(0 );
1448  }
1449  else
1450  {
1451    return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ;
1452  }
1453}
1454
1455TComPic* TEncTop::getPic( Int poc )
1456{
1457  TComList<TComPic*>* listPic = getListPic();
1458  TComPic* pcPic = NULL;
1459  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1460  {
1461    if( (*it)->getPOC() == poc )
1462    {
1463      pcPic = *it ;
1464      break ;
1465    }
1466  }
1467  return pcPic;
1468}
[1200]1469
[608]1470#endif
1471
[1200]1472#if NH_3D_VSO
1473Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset, Int maxCuHeight )
[608]1474{
1475  TRenModel* rendererModel = m_cRdCost.getRenModel(); 
[1200]1476  rendererModel->setupPart( iHorOffset, std::min( maxCuHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; 
[608]1477 
1478  Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ];
1479
1480  // setup base views
1481  Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent );
1482
1483  for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ )
1484  {
1485    Int iBaseViewSIdx;
1486    Int iVideoDistMode;
1487    Int iDepthDistMode;
1488
1489    m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode );
1490
1491    AOT( iVideoDistMode < 0 || iVideoDistMode > 2 );
1492
1493    Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ];
1494
1495    TComPicYuv* pcPicYuvVideoRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true  );
1496    TComPicYuv* pcPicYuvDepthRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true  );
1497    TComPicYuv* pcPicYuvVideoOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false );
1498    TComPicYuv* pcPicYuvDepthOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false );   
1499
1500    TComPicYuv* pcPicYuvVideoRef  = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg  : NULL;
1501    TComPicYuv* pcPicYuvDepthRef  = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg  : NULL;
1502
1503    TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg  : pcPicYuvVideoRec;
1504    TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg  : pcPicYuvDepthRec;
1505
1506    AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) );
1507    AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) );
1508    AOT( pcPicYuvDepthTest == NULL );
1509    AOT( pcPicYuvVideoTest == NULL );
1510
1511    rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef );
1512  }
1513
1514  rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 );
1515  // setup virtual views
1516  Int iNumOfSV  = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent );
1517  for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
1518  {
1519    Int iOrgRefBaseViewSIdx;
1520    Int iLeftBaseViewSIdx;
1521    Int iRightBaseViewSIdx;
1522    Int iSynthViewRelNum;
1523    Int iModelNum;
1524    Int iBlendMode;
1525    m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
1526
1527    Int iLeftBaseViewIdx    = -1;
1528    Int iRightBaseViewIdx   = -1;
1529
1530    TComPicYuv* pcPicYuvOrgRef  = NULL;
1531    Int**      ppiShiftLUTLeft  = NULL;
1532    Int**      ppiShiftLUTRight = NULL;
1533    Int**      ppiBaseShiftLUTLeft  = NULL;
1534    Int**      ppiBaseShiftLUTRight = NULL;
1535
1536
1537    Int        iDistToLeft      = -1;
1538
1539    Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum );
1540
1541    if ( iLeftBaseViewSIdx != -1 )
1542    {
1543      iLeftBaseViewIdx   = m_cameraParameters->getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
1544      ppiShiftLUTLeft    = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
1545    }
1546
1547    if ( iRightBaseViewSIdx != -1 )
1548    {
1549      iRightBaseViewIdx  = m_cameraParameters->getBaseSortedId2Id()   [iRightBaseViewSIdx ];
1550      ppiShiftLUTRight   = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
1551    }
1552
1553    if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
1554    {
1555      iDistToLeft          = m_cameraParameters->getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
1556      ppiBaseShiftLUTLeft  = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
1557      ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
1558
1559    }
1560
1561    if ( iOrgRefBaseViewSIdx != -1 )
1562    {
1563      pcPicYuvOrgRef = m_ivPicLists->getPicYuv(  m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false );
1564      AOF ( pcPicYuvOrgRef );
1565    }
1566
1567    rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
1568  }
1569}
1570#endif
[1200]1571
[56]1572//! \}
Note: See TracBrowser for help on using the repository browser.