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

Last change on this file since 1314 was 1310, checked in by tech, 9 years ago

Fixes:

NH_MV_FIX_TICKET_105 layer_set_idx_for_ols_minus1 length
NH_3D_FIX_TICKET_98 Writing of depth intra skip flag
NH_MV_FIX_TICKET_100 Extra slice header bits

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