source: 3DVCSoftware/branches/HTM-15.2-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 1373

Last change on this file since 1373 was 1373, checked in by tech, 8 years ago

Macro fixes.

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