source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncGOP.cpp @ 47

Last change on this file since 47 was 42, checked in by tech, 13 years ago

Nokia (Flexible Coding Order)
Ericsson ( High Level Syntax )
changes

  • Property svn:eol-style set to native
File size: 36.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-2011, 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 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
35
36/** \file     TEncPic.cpp
37    \brief    GOP encoder class
38*/
39
40#include "TEncTop.h"
41#include "TEncGOP.h"
42#include "TEncAnalyze.h"
43#include "../libmd5/MD5.h"
44#include "../TLibCommon/SEI.h"
45
46#include <time.h>
47
48#include "../../App/TAppEncoder/TAppEncTop.h"
49
50// ====================================================================================================================
51// Constructor / destructor / initialization / destroy
52// ====================================================================================================================
53
54TEncPic::TEncPic()
55{
56  m_pcCfg               = NULL;
57  m_pcSliceEncoder      = NULL;
58  m_pcListPic           = NULL;
59
60  m_pcEntropyCoder      = NULL;
61  m_pcCavlcCoder        = NULL;
62  m_pcSbacCoder         = NULL;
63  m_pcBinCABAC          = NULL;
64#if DEPTH_MAP_GENERATION
65  m_pcDepthMapGenerator = NULL;
66#endif
67#if HHI_INTER_VIEW_RESIDUAL_PRED
68  m_pcResidualGenerator = NULL;
69#endif
70
71#if DCM_DECODING_REFRESH
72  m_bRefreshPending     = 0;
73  m_uiPOCCDR            = 0;
74#endif
75
76  return;
77}
78
79TEncPic::~TEncPic()
80{
81}
82
83/** Create list to contain pointers to LCU start addresses of slice.
84 * \param iWidth, iHeight are picture width, height. iMaxCUWidth, iMaxCUHeight are LCU width, height.
85 */
86Void  TEncPic::create( Int iWidth, Int iHeight, UInt iMaxCUWidth, UInt iMaxCUHeight )
87{
88  UInt uiWidthInCU       = ( iWidth %iMaxCUWidth  ) ? iWidth /iMaxCUWidth  + 1 : iWidth /iMaxCUWidth;
89  UInt uiHeightInCU      = ( iHeight%iMaxCUHeight ) ? iHeight/iMaxCUHeight + 1 : iHeight/iMaxCUHeight;
90  UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
91  m_uiStoredStartCUAddrForEncodingSlice = new UInt [uiNumCUsInFrame+1];
92  m_uiStoredStartCUAddrForEncodingEntropySlice = new UInt [uiNumCUsInFrame+1];
93}
94
95Void  TEncPic::destroy()
96{
97  delete [] m_uiStoredStartCUAddrForEncodingSlice; m_uiStoredStartCUAddrForEncodingSlice = NULL;
98  delete [] m_uiStoredStartCUAddrForEncodingEntropySlice; m_uiStoredStartCUAddrForEncodingEntropySlice = NULL;
99}
100
101Void TEncPic::init ( TEncTop* pcTEncTop )
102{
103  m_pcEncTop     = pcTEncTop;
104  m_pcCfg                = pcTEncTop;
105  m_pcSliceEncoder       = pcTEncTop->getSliceEncoder();
106  m_pcListPic            = pcTEncTop->getListPic();
107
108  m_pcEntropyCoder       = pcTEncTop->getEntropyCoder();
109  m_pcCavlcCoder         = pcTEncTop->getCavlcCoder();
110  m_pcSbacCoder          = pcTEncTop->getSbacCoder();
111  m_pcBinCABAC           = pcTEncTop->getBinCABAC();
112  m_pcLoopFilter         = pcTEncTop->getLoopFilter();
113  m_pcBitCounter         = pcTEncTop->getBitCounter();
114#if DEPTH_MAP_GENERATION
115  m_pcDepthMapGenerator  = pcTEncTop->getDepthMapGenerator();
116#endif
117#if HHI_INTER_VIEW_RESIDUAL_PRED
118  m_pcResidualGenerator  = pcTEncTop->getResidualGenerator();
119#endif
120
121  // Adaptive Loop filter
122  m_pcAdaptiveLoopFilter = pcTEncTop->getAdaptiveLoopFilter();
123  //--Adaptive Loop filter
124#if MTK_SAO
125  m_pcSAO                = pcTEncTop->getSAO();
126#endif
127  m_pcRdCost             = pcTEncTop->getRdCost();
128
129}
130
131// ====================================================================================================================
132// Public member functions
133// ====================================================================================================================
134
135Void TEncPic::compressPic( TComBitstream* pcBitstreamOut, TComPicYuv cPicOrg, TComPic* pcPic, TComPicYuv* pcPicYuvRecOut,
136               TComPic* pcOrgRefList[2][MAX_REF_PIC_NUM], Bool&  rbSeqFirst, TComList<TComPic*>& rcListPic  )
137{
138  TComSlice*      pcSlice;
139
140      //-- For time output for each slice
141      long iBeforeTime = clock();
142
143      //  Bitstream reset
144      pcBitstreamOut->resetBits();
145      pcBitstreamOut->rewindStreamPacket();
146
147      //  Slice data initialization
148      pcPic->clearSliceBuffer();
149      assert(pcPic->getNumAllocatedSlice() == 1);
150      m_pcSliceEncoder->setSliceIdx(0);
151      pcPic->setCurrSliceIdx(0);
152      m_pcSliceEncoder->initEncSlice ( pcPic, pcSlice );
153      pcSlice->setSliceIdx(0);
154
155      //  Set SPS
156      pcSlice->setSPS( m_pcEncTop->getSPS() );
157      pcSlice->setPPS( m_pcEncTop->getPPS() );
158      pcSlice->setPPSId( pcSlice->getPPS()->getPPSId() );
159
160  // set mutliview parameters
161      pcSlice->initMultiviewSlice( pcPic->getCodedScale(), pcPic->getCodedOffset() );
162
163#if DCM_DECODING_REFRESH
164      // Set the nal unit type
165      if( pcSlice->getPOC() == 0 )
166        pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_IDR );
167      else
168        pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE );
169
170      //pcSlice->setNalUnitType(getNalUnitType(uiPOCCurr));
171      // Do decoding refresh marking if any
172      pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, rcListPic);
173#endif
174
175// GT FIX
176  std::vector<TComPic*> apcSpatRefPics = m_pcEncTop->getEncTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_pcEncTop->isDepthCoder() );
177  TComPic * const pcTexturePic = m_pcEncTop->isDepthCoder() ? m_pcEncTop->getEncTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
178  assert( ! m_pcEncTop->isDepthCoder() || pcTexturePic != NULL );
179  pcSlice->setTexturePic( pcTexturePic );
180
181  pcSlice->setRefPicListFromGOPSTring( rcListPic, apcSpatRefPics );
182
183#if HHI_VSO
184  m_pcEncTop->getEncTop()->setMVDPic(pcPic->getViewIdx(), pcSlice->getPOC(), pcPic->getMVDReferenceInfo() );
185
186
187  Bool bUseVSO = m_pcEncTop->getUseVSO();
188  m_pcRdCost->setUseVSO( bUseVSO );
189
190  if ( bUseVSO )
191  {
192    Int iVSOMode = m_pcEncTop->getVSOMode();
193    m_pcRdCost->setVSOMode( iVSOMode  );
194#if HHI_VSO_DIST_INT
195    m_pcRdCost->setAllowNegDist( m_pcEncTop->getAllowNegDist() );
196#endif
197
198    if ( iVSOMode == 4 )
199    {
200      m_pcEncTop->getEncTop()->setupRenModel( pcSlice->getPOC(), pcPic->getViewIdx(), m_pcEncTop->isDepthCoder() ? 1 : 0 );
201    }
202    else
203  {
204    m_pcRdCost->setRefDataFromMVDInfo( pcPic->getMVDReferenceInfo() );
205  }
206  }
207#endif
208
209#if HHI_INTERVIEW_SKIP
210  if ( m_pcEncTop->getInterViewSkip() )
211  {
212    m_pcEncTop->getEncTop()->getUsedPelsMap( pcPic->getViewIdx(), pcPic->getPOC(), pcPic->getUsedPelsMap() );
213  }
214#endif
215
216      pcSlice->setNoBackPredFlag( false );
217#if DCM_COMB_LIST
218      if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
219#else
220      if ( pcSlice->getSliceType() == B_SLICE )
221#endif
222      {
223        if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
224        {
225          pcSlice->setNoBackPredFlag( true );
226          int i;
227          for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
228          {
229            if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
230            {
231              pcSlice->setNoBackPredFlag( false );
232              break;
233            }
234          }
235        }
236      }
237
238#if DCM_COMB_LIST
239      if(pcSlice->getNoBackPredFlag())
240      {
241        pcSlice->setNumRefIdx(REF_PIC_LIST_C, -1);
242      }
243      pcSlice->generateCombinedList();
244#endif
245
246      /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice
247      //  Slice compression
248      if (m_pcCfg->getUseASR())
249      {
250        m_pcSliceEncoder->setSearchRange(pcSlice);
251      }
252#ifdef ROUNDING_CONTROL_BIPRED
253      Bool b = true;
254      if (m_pcCfg->getUseRoundingControlBipred())
255      {
256        if (m_pcCfg->getCodedPictureBufferSize()==1)
257          b = ((pcSlice->getPOC()&1)==0);
258        else
259          b = (pcSlice->isReferenced() == 0);
260      }
261
262#if HIGH_ACCURACY_BI
263      pcSlice->setRounding(false);
264#else
265      pcSlice->setRounding(b);
266#endif
267#endif
268
269      UInt uiStartCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries
270      UInt uiStartCUAddrSlice    = 0; // used to keep track of current slice's starting CU addr.
271      pcSlice->setSliceCurStartCUAddr( uiStartCUAddrSlice ); // Setting "start CU addr" for current slice
272      memset(m_uiStoredStartCUAddrForEncodingSlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()+1));
273
274      UInt uiStartCUAddrEntropySliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries
275      UInt uiStartCUAddrEntropySlice    = 0; // used to keep track of current Entropy slice's starting CU addr.
276      pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice ); // Setting "start CU addr" for current Entropy slice
277      memset(m_uiStoredStartCUAddrForEncodingEntropySlice, 0, sizeof(UInt) * (pcPic->getPicSym()->getNumberOfCUsInFrame()+1));
278
279      UInt uiNextCUAddr = 0;
280      m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++]                = uiNextCUAddr;
281      m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++]  = uiNextCUAddr;
282
283#if DEPTH_MAP_GENERATION
284      // init view component and predict virtual depth map
285      m_pcDepthMapGenerator->initViewComponent( pcPic );
286      m_pcDepthMapGenerator->predictDepthMap  ( pcPic );
287#if HHI_INTER_VIEW_MOTION_PRED
288      m_pcDepthMapGenerator->covertOrgDepthMap( pcPic );
289#endif
290#if HHI_INTER_VIEW_RESIDUAL_PRED
291      m_pcResidualGenerator->initViewComponent( pcPic );
292#endif
293#endif
294
295      while(uiNextCUAddr<pcPic->getPicSym()->getNumberOfCUsInFrame()) // determine slice boundaries
296      {
297        pcSlice->setNextSlice       ( false );
298        pcSlice->setNextEntropySlice( false );
299        assert(pcPic->getNumAllocatedSlice() == uiStartCUAddrSliceIdx);
300        m_pcSliceEncoder->precompressSlice( pcPic );
301        m_pcSliceEncoder->compressSlice   ( pcPic );
302
303        Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextEntropySlice());
304        if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE))
305        {
306          uiStartCUAddrSlice                                              = pcSlice->getSliceCurEndCUAddr();
307          // Reconstruction slice
308          m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++]  = uiStartCUAddrSlice;
309          // Entropy slice
310          if (uiStartCUAddrEntropySliceIdx>0 && m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx-1] != uiStartCUAddrSlice)
311          {
312            m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++]  = uiStartCUAddrSlice;
313          }
314
315          if (uiStartCUAddrSlice < pcPic->getPicSym()->getNumberOfCUsInFrame())
316          {
317            pcPic->allocateNewSlice();
318            pcPic->setCurrSliceIdx                  ( uiStartCUAddrSliceIdx-1 );
319            m_pcSliceEncoder->setSliceIdx           ( uiStartCUAddrSliceIdx-1 );
320            pcSlice = pcPic->getSlice               ( uiStartCUAddrSliceIdx-1 );
321            pcSlice->copySliceInfo                  ( pcPic->getSlice(0)      );
322            pcSlice->setSliceIdx                    ( uiStartCUAddrSliceIdx-1 );
323            pcSlice->setSliceCurStartCUAddr         ( uiStartCUAddrSlice      );
324            pcSlice->setEntropySliceCurStartCUAddr  ( uiStartCUAddrSlice      );
325            pcSlice->setSliceBits(0);
326          }
327        }
328        else if (pcSlice->isNextEntropySlice() || (bNoBinBitConstraintViolated && m_pcCfg->getEntropySliceMode()==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE))
329        {
330          uiStartCUAddrEntropySlice                                                     = pcSlice->getEntropySliceCurEndCUAddr();
331          m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++]  = uiStartCUAddrEntropySlice;
332          pcSlice->setEntropySliceCurStartCUAddr( uiStartCUAddrEntropySlice );
333        }
334        else
335        {
336          uiStartCUAddrSlice                                                            = pcSlice->getSliceCurEndCUAddr();
337          uiStartCUAddrEntropySlice                                                     = pcSlice->getEntropySliceCurEndCUAddr();
338        }
339
340        uiNextCUAddr = (uiStartCUAddrSlice > uiStartCUAddrEntropySlice) ? uiStartCUAddrSlice : uiStartCUAddrEntropySlice;
341      }
342      m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx++]                = pcSlice->getSliceCurEndCUAddr();
343      m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx++]  = pcSlice->getSliceCurEndCUAddr();
344
345      pcSlice = pcPic->getSlice(0);
346#if MTK_SAO  // PRE_DF
347      SAOParam cSaoParam;
348#endif
349
350#if HHI_INTER_VIEW_RESIDUAL_PRED
351      // set residual picture
352      m_pcResidualGenerator->setRecResidualPic( pcPic );
353#endif
354#if DEPTH_MAP_GENERATION
355      // update virtual depth map
356      m_pcDepthMapGenerator->updateDepthMap( pcPic );
357#endif
358
359      //-- Loop filter
360      m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterAlphaC0Offget(), m_pcCfg->getLoopFilterBetaOffget());
361      m_pcLoopFilter->loopFilterPic( pcPic );
362
363#if MTK_NONCROSS_INLOOP_FILTER
364      pcSlice = pcPic->getSlice(0);
365
366      if(pcSlice->getSPS()->getUseALF())
367      {
368        if(pcSlice->getSPS()->getLFCrossSliceBoundaryFlag())
369        {
370          m_pcAdaptiveLoopFilter->setUseNonCrossAlf(false);
371        }
372        else
373        {
374          UInt uiNumSlices = uiStartCUAddrSliceIdx-1;
375          m_pcAdaptiveLoopFilter->setUseNonCrossAlf( (uiNumSlices > 1)  );
376          if(m_pcAdaptiveLoopFilter->getUseNonCrossAlf())
377          {
378            m_pcAdaptiveLoopFilter->setNumSlicesInPic( uiNumSlices );
379            m_pcAdaptiveLoopFilter->createSlice();
380
381            //set the startLCU and endLCU addr. to ALF slices
382            for(UInt i=0; i< uiNumSlices ; i++)
383            {
384              (*m_pcAdaptiveLoopFilter)[i].create(pcPic, i,
385                                                  m_uiStoredStartCUAddrForEncodingSlice[i],
386                                                  m_uiStoredStartCUAddrForEncodingSlice[i+1]-1
387                                                  );
388
389            }
390          }
391        }
392      }
393#endif
394      /////////////////////////////////////////////////////////////////////////////////////////////////// File writing
395      // Set entropy coder
396      m_pcEntropyCoder->setEntropyCoder   ( m_pcCavlcCoder, pcSlice );
397
398      /* write various header sets.
399       * The header sets are written into a separate bitstream buffer to
400       * allow SEI messages that are calculated after the picture has been
401       * encoded to be sent before the picture.
402       */
403      TComBitstream bs_SPS_PPS_SEI;
404      bs_SPS_PPS_SEI.create(512); /* TODO: this should dynamically resize */
405      if ( rbSeqFirst )
406      {
407        m_pcEntropyCoder->setBitstream(&bs_SPS_PPS_SEI);
408
409        m_pcEntropyCoder->encodeSPS( pcSlice->getSPS() );
410        bs_SPS_PPS_SEI.write( 1, 1 );
411        bs_SPS_PPS_SEI.writeAlignZero();
412        // generate start code
413        bs_SPS_PPS_SEI.write( 1, 32);
414
415        m_pcEntropyCoder->encodePPS( pcSlice->getPPS() );
416        bs_SPS_PPS_SEI.write( 1, 1 );
417        bs_SPS_PPS_SEI.writeAlignZero();
418        // generate start code
419        bs_SPS_PPS_SEI.write( 1, 32);
420        rbSeqFirst = false;
421      }
422
423      /* use the main bitstream buffer for storing the marshalled picture */
424      m_pcEntropyCoder->setBitstream(pcBitstreamOut);
425
426      uiStartCUAddrSliceIdx = 0;
427      uiStartCUAddrSlice    = 0;
428      pcBitstreamOut->allocateMemoryForSliceLocations( pcPic->getPicSym()->getNumberOfCUsInFrame() ); // Assuming number of slices <= number of LCU. Needs to be changed for sub-LCU slice coding.
429      pcBitstreamOut->setSliceCount( 0 );                                      // intialize number of slices to zero, used while converting RBSP to NALU
430
431      uiStartCUAddrEntropySliceIdx = 0;
432      uiStartCUAddrEntropySlice    = 0;
433      uiNextCUAddr                 = 0;
434      pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx);
435      while (uiNextCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame()) // Iterate over all slices
436      {
437        pcSlice->setNextSlice       ( false );
438        pcSlice->setNextEntropySlice( false );
439        if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx])
440        {
441          pcSlice = pcPic->getSlice(uiStartCUAddrSliceIdx);
442          pcPic->setCurrSliceIdx(uiStartCUAddrSliceIdx);
443          m_pcSliceEncoder->setSliceIdx(uiStartCUAddrSliceIdx);
444          assert(uiStartCUAddrSliceIdx == pcSlice->getSliceIdx());
445          // Reconstruction slice
446          pcSlice->setSliceCurStartCUAddr( uiNextCUAddr );  // to be used in encodeSlice() + context restriction
447          pcSlice->setSliceCurEndCUAddr  ( m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx+1 ] );
448          // Entropy slice
449          pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr );  // to be used in encodeSlice() + context restriction
450          pcSlice->setEntropySliceCurEndCUAddr  ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] );
451
452          pcSlice->setNextSlice       ( true );
453
454          uiStartCUAddrSliceIdx++;
455          uiStartCUAddrEntropySliceIdx++;
456        }
457        else if (uiNextCUAddr == m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx])
458        {
459          // Entropy slice
460          pcSlice->setEntropySliceCurStartCUAddr( uiNextCUAddr );  // to be used in encodeSlice() + context restriction
461          pcSlice->setEntropySliceCurEndCUAddr  ( m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx+1 ] );
462
463          pcSlice->setNextEntropySlice( true );
464
465          uiStartCUAddrEntropySliceIdx++;
466        }
467
468        // Get ready for writing slice header (other than the first one in the picture)
469        if (uiNextCUAddr!=0)
470        {
471          m_pcEntropyCoder->setEntropyCoder   ( m_pcCavlcCoder, pcSlice );
472          m_pcEntropyCoder->setBitstream      ( pcBitstreamOut          );
473          m_pcEntropyCoder->resetEntropy      ();
474        }
475
476      // write SliceHeader
477      m_pcEntropyCoder->encodeSliceHeader ( pcSlice                 );
478
479      // is it needed?
480      if ( pcSlice->getSymbolMode() )
481      {
482        m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC );
483        m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
484        m_pcEntropyCoder->resetEntropy    ();
485      }
486
487        if (uiNextCUAddr==0)  // Compute ALF params and write only for first slice header
488        {
489          // adaptive loop filter
490#if MTK_SAO
491          if ( pcSlice->getSPS()->getUseALF() || (pcSlice->getSPS()->getUseSAO()) )
492#else
493          if ( pcSlice->getSPS()->getUseALF())
494#endif
495          {
496            ALFParam cAlfParam;
497#if TSB_ALF_HEADER
498            m_pcAdaptiveLoopFilter->setNumCUsInFrame(pcPic);
499#endif
500            m_pcAdaptiveLoopFilter->allocALFParam(&cAlfParam);
501
502            // set entropy coder for RD
503            if ( pcSlice->getSymbolMode() )
504            {
505              m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice );
506            }
507            else
508            {
509              m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
510            }
511            m_pcEntropyCoder->resetEntropy    ();
512            m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
513
514            m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder );
515#if MTK_SAO  // PostDF
516            {
517              if (pcSlice->getSPS()->getUseSAO())
518              {
519                m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcCfg->getUseSBACRD() ?  m_pcEncTop->getRDGoOnSbacCoder() : NULL);
520                m_pcSAO->SAOProcess(pcPic->getSlice(0)->getLambda());
521                m_pcSAO->copyQaoData(&cSaoParam);
522                m_pcSAO->endSaoEnc();
523              }
524            }
525#endif
526            UInt uiMaxAlfCtrlDepth;
527
528            UInt64 uiDist, uiBits;
529#if MTK_SAO
530            if ( pcSlice->getSPS()->getUseALF())
531#endif
532              m_pcAdaptiveLoopFilter->ALFProcess( &cAlfParam, pcPic->getSlice(0)->getLambda(), uiDist, uiBits, uiMaxAlfCtrlDepth );
533#if MTK_SAO
534            else
535              cAlfParam.cu_control_flag = 0;
536#endif
537            m_pcAdaptiveLoopFilter->endALFEnc();
538
539            // set entropy coder for writing
540            m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC );
541            if ( pcSlice->getSymbolMode() )
542            {
543              m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
544            }
545            else
546            {
547              m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
548            }
549            m_pcEntropyCoder->resetEntropy    ();
550            m_pcEntropyCoder->setBitstream    ( pcBitstreamOut );
551            if (cAlfParam.cu_control_flag)
552            {
553              m_pcEntropyCoder->setAlfCtrl( true );
554              m_pcEntropyCoder->setMaxAlfCtrlDepth(uiMaxAlfCtrlDepth);
555              if (pcSlice->getSymbolMode() == 0)
556              {
557                m_pcCavlcCoder->setAlfCtrl(true);
558                m_pcCavlcCoder->setMaxAlfCtrlDepth(uiMaxAlfCtrlDepth); //D0201
559              }
560            }
561            else
562            {
563              m_pcEntropyCoder->setAlfCtrl(false);
564            }
565#if MTK_SAO
566            if (pcSlice->getSPS()->getUseSAO())
567            {
568              m_pcEntropyCoder->encodeSaoParam(&cSaoParam);
569            }
570            if (pcSlice->getSPS()->getUseALF())
571#endif
572            m_pcEntropyCoder->encodeAlfParam(&cAlfParam);
573
574#if TSB_ALF_HEADER
575            if(cAlfParam.cu_control_flag)
576            {
577              m_pcEntropyCoder->encodeAlfCtrlParam(&cAlfParam);
578            }
579#endif
580            m_pcAdaptiveLoopFilter->freeALFParam(&cAlfParam);
581          }
582        }
583
584        // File writing
585        m_pcSliceEncoder->encodeSlice( pcPic, pcBitstreamOut );
586
587        //  End of bitstream & byte align
588        pcBitstreamOut->write( 1, 1 );
589        pcBitstreamOut->writeAlignZero();
590
591        UInt uiBoundingAddrSlice, uiBoundingAddrEntropySlice;
592        uiBoundingAddrSlice        = m_uiStoredStartCUAddrForEncodingSlice[uiStartCUAddrSliceIdx];
593        uiBoundingAddrEntropySlice = m_uiStoredStartCUAddrForEncodingEntropySlice[uiStartCUAddrEntropySliceIdx];
594        uiNextCUAddr               = min(uiBoundingAddrSlice, uiBoundingAddrEntropySlice);
595        if (uiNextCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame())   // if more slices to be encoded insert start code
596        {
597          UInt uiSliceCount = pcBitstreamOut->getSliceCount();
598          pcBitstreamOut->setSliceByteLocation( uiSliceCount, (pcBitstreamOut->getNumberOfWrittenBits()>>3) );
599          pcBitstreamOut->setSliceCount( uiSliceCount+1 );
600          pcBitstreamOut->write( 1, 32);
601        }
602      } // end iteration over slices
603
604
605#if MTK_NONCROSS_INLOOP_FILTER
606      if(pcSlice->getSPS()->getUseALF())
607      {
608        if(m_pcAdaptiveLoopFilter->getUseNonCrossAlf())
609          m_pcAdaptiveLoopFilter->destroySlice();
610      }
611#endif
612
613
614      pcBitstreamOut->flushBuffer();
615      pcBitstreamOut->convertRBSPToPayload(0);
616
617/*#if AMVP_BUFFERCOMPRESS
618      pcPic->compressMotion(); // moved to end of access unit
619#endif */
620      pcBitstreamOut->freeMemoryAllocatedForSliceLocations();
621
622      //-- For time output for each slice
623      Double dEncTime = (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
624
625      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), pcBitstreamOut->getNumberOfWrittenBits(), dEncTime );
626
627#if FIXED_ROUNDING_FRAME_MEMORY
628      pcPic->getPicYuvRec()->xFixedRoundingPic();
629#endif
630
631      if (m_pcCfg->getPictureDigestEnabled()) {
632        /* calculate MD5sum for entire reconstructed picture */
633        SEIpictureDigest sei_recon_picture_digest;
634        sei_recon_picture_digest.method = SEIpictureDigest::MD5;
635        calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest);
636        printf("[MD5:%s] ", digestToString(sei_recon_picture_digest.digest));
637
638        TComBitstream seiBs;
639        seiBs.create(1024);
640        /* write the SEI messages */
641#if BITSTREAM_EXTRACTION
642        sei_recon_picture_digest.setLayerId( pcSlice->getLayerId() );
643#endif
644        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
645        m_pcEntropyCoder->setBitstream(&seiBs);
646        m_pcEntropyCoder->encodeSEI(sei_recon_picture_digest);
647        /* and trailing bits */
648        seiBs.write(1, 1);
649        seiBs.writeAlignZero();
650        seiBs.flushBuffer();
651        seiBs.convertRBSPToPayload(0);
652
653        /* append the SEI message after any SPS/PPS */
654        /* the following loop is a work around current limitations in
655         * TComBitstream that won't be fixed before HM-3.0 */
656        UChar *seiData = reinterpret_cast<UChar *>(seiBs.getStartStream());
657        for (Int i = 0; i < seiBs.getNumberOfWrittenBits()/8; i++)
658        {
659          bs_SPS_PPS_SEI.write(seiData[i], 8);
660        }
661        bs_SPS_PPS_SEI.write(1, 32);
662        seiBs.destroy();
663      }
664
665      /* insert the bs_SPS_PPS_SEI before the pcBitstreamOut */
666      bs_SPS_PPS_SEI.flushBuffer();
667      pcBitstreamOut->insertAt(bs_SPS_PPS_SEI, 0);
668
669      bs_SPS_PPS_SEI.destroy();
670      pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
671
672      pcPic->setReconMark   ( true );
673
674}
675
676Void TEncPic::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits )
677{
678  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
679  Bool bCalcDist = false;
680
681  m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterAlphaC0Offget(), m_pcCfg->getLoopFilterBetaOffget());
682  m_pcLoopFilter->loopFilterPic( pcPic );
683
684  m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice );
685  m_pcEntropyCoder->resetEntropy    ();
686  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
687
688  // Adaptive Loop filter
689  if( pcSlice->getSPS()->getUseALF() )
690  {
691    ALFParam cAlfParam;
692#if TSB_ALF_HEADER
693    m_pcAdaptiveLoopFilter->setNumCUsInFrame(pcPic);
694#endif
695    m_pcAdaptiveLoopFilter->allocALFParam(&cAlfParam);
696
697    m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder);
698
699    UInt uiMaxAlfCtrlDepth;
700    m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, pcSlice->getLambda(), ruiDist, ruiBits, uiMaxAlfCtrlDepth );
701    m_pcAdaptiveLoopFilter->endALFEnc();
702    m_pcAdaptiveLoopFilter->freeALFParam(&cAlfParam);
703  }
704
705  m_pcEntropyCoder->resetEntropy    ();
706  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
707
708  if (!bCalcDist)
709    ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec());
710}
711
712// ====================================================================================================================
713// Protected member functions
714// ====================================================================================================================
715
716UInt64 TEncPic::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1)
717{
718  Int     x, y;
719  Pel*  pSrc0   = pcPic0 ->getLumaAddr();
720  Pel*  pSrc1   = pcPic1 ->getLumaAddr();
721#if IBDI_DISTORTION
722  Int  iShift = g_uiBitIncrement;
723  Int  iOffset = 1<<(g_uiBitIncrement-1);
724#else
725  UInt  uiShift = g_uiBitIncrement<<1;
726#endif
727  Int   iTemp;
728
729  Int   iStride = pcPic0->getStride();
730  Int   iWidth  = pcPic0->getWidth();
731  Int   iHeight = pcPic0->getHeight();
732
733  UInt64  uiTotalDiff = 0;
734
735  for( y = 0; y < iHeight; y++ )
736  {
737    for( x = 0; x < iWidth; x++ )
738    {
739#if IBDI_DISTORTION
740      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
741#else
742      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
743#endif
744    }
745    pSrc0 += iStride;
746    pSrc1 += iStride;
747  }
748
749  iHeight >>= 1;
750  iWidth  >>= 1;
751  iStride >>= 1;
752
753  pSrc0  = pcPic0->getCbAddr();
754  pSrc1  = pcPic1->getCbAddr();
755
756  for( y = 0; y < iHeight; y++ )
757  {
758    for( x = 0; x < iWidth; x++ )
759    {
760#if IBDI_DISTORTION
761      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
762#else
763      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
764#endif
765    }
766    pSrc0 += iStride;
767    pSrc1 += iStride;
768  }
769
770  pSrc0  = pcPic0->getCrAddr();
771  pSrc1  = pcPic1->getCrAddr();
772
773  for( y = 0; y < iHeight; y++ )
774  {
775    for( x = 0; x < iWidth; x++ )
776    {
777#if IBDI_DISTORTION
778      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
779#else
780      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
781#endif
782    }
783    pSrc0 += iStride;
784    pSrc1 += iStride;
785  }
786
787  return uiTotalDiff;
788}
789
790Void TEncPic::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, UInt uibits, Double dEncTime )
791{
792  Int     x, y;
793  UInt64 uiSSDY  = 0;
794  UInt64 uiSSDU  = 0;
795  UInt64 uiSSDV  = 0;
796
797  Double  dYPSNR  = 0.0;
798  Double  dUPSNR  = 0.0;
799  Double  dVPSNR  = 0.0;
800
801  //===== calculate PSNR =====
802  Pel*  pOrg    = pcPic ->getPicYuvOrg()->getLumaAddr();
803  Pel*  pRec    = pcPicD->getLumaAddr();
804  Int   iStride = pcPicD->getStride();
805
806  Int   iWidth;
807  Int   iHeight;
808
809  iWidth  = pcPicD->getWidth () - m_pcEncTop->getPad(0);
810  iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1);
811
812  Int   iSize   = iWidth*iHeight;
813
814  UInt   maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8));
815  Double fRefValueY = (double) maxval * maxval * iSize;
816  Double fRefValueC = fRefValueY / 4.0;
817
818  for( y = 0; y < iHeight; y++ )
819  {
820    for( x = 0; x < iWidth; x++ )
821    {
822      Int iDiff = (Int)( pOrg[x] - pRec[x] );
823      uiSSDY   += iDiff * iDiff;
824    }
825    pOrg += iStride;
826    pRec += iStride;
827  }
828
829#if HHI_VSO_PRINT_DIST
830  if ( m_pcRdCost->getUseRenModel() )
831  {
832    TRenModel*  pcRenModel = m_pcEncTop->getEncTop()->getRenModel();
833    Int64 iDistVSOY, iDistVSOU, iDistVSOV;
834    pcRenModel->getTotalSSE( iDistVSOY, iDistVSOU, iDistVSOV );
835    dYPSNR = ( iDistVSOY ? 10.0 * log10( fRefValueY / (Double) iDistVSOY ) : 99.99 );
836    dUPSNR = ( iDistVSOU ? 10.0 * log10( fRefValueC / (Double) iDistVSOU ) : 99.99 );
837    dVPSNR = ( iDistVSOV ? 10.0 * log10( fRefValueC / (Double) iDistVSOV ) : 99.99 );
838  }
839  else
840#endif
841  {
842  iHeight >>= 1;
843  iWidth  >>= 1;
844  iStride >>= 1;
845  pOrg  = pcPic ->getPicYuvOrg()->getCbAddr();
846  pRec  = pcPicD->getCbAddr();
847
848  for( y = 0; y < iHeight; y++ )
849  {
850    for( x = 0; x < iWidth; x++ )
851    {
852      Int iDiff = (Int)( pOrg[x] - pRec[x] );
853      uiSSDU   += iDiff * iDiff;
854    }
855    pOrg += iStride;
856    pRec += iStride;
857  }
858
859  pOrg  = pcPic ->getPicYuvOrg()->getCrAddr();
860  pRec  = pcPicD->getCrAddr();
861
862  for( y = 0; y < iHeight; y++ )
863  {
864    for( x = 0; x < iWidth; x++ )
865    {
866      Int iDiff = (Int)( pOrg[x] - pRec[x] );
867      uiSSDV   += iDiff * iDiff;
868    }
869    pOrg += iStride;
870    pRec += iStride;
871  }
872  dYPSNR            = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 );
873  dUPSNR            = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 );
874  dVPSNR            = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 );
875  }
876  // fix: total bits should consider slice size bits (32bit)
877  uibits += 32;
878
879#if RVM_VCEGAM10
880  m_vRVM_RP.push_back( uibits );
881#endif
882
883  //===== add PSNR =====
884  m_pcEncTop->m_cAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
885  TComSlice*  pcSlice = pcPic->getSlice(0);
886  if (pcSlice->isIntra())
887  {
888    m_pcEncTop->m_cAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
889  }
890  if (pcSlice->isInterP())
891  {
892    m_pcEncTop->m_cAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
893  }
894  if (pcSlice->isInterB())
895  {
896    m_pcEncTop->m_cAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
897  }
898  if(pcPic->getViewIdx()!=-1)
899  {
900    if(! m_pcEncTop->isDepthCoder())
901    {
902      printf("\nView \t\t%2d\t POC %4d ( %c-SLICE, QP %d ) %10d bits ",
903      pcSlice->getViewIdx(),
904      pcSlice->getPOC(),
905      pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
906      pcSlice->getSliceQp(),
907      uibits );
908    }
909    else
910    {
911      printf("\nDepth View \t%2d\t POC %4d ( %c-SLICE, QP %d ) %10d bits ",
912            pcSlice->getViewIdx(),
913            pcSlice->getPOC(),
914            pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
915            pcSlice->getSliceQp(),
916            uibits );
917    }
918  }
919  else
920  {
921    printf("\nPOC %4d ( %c-SLICE, QP %d ) %10d bits ",
922           pcSlice->getPOC(),
923           pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
924           pcSlice->getSliceQp(),
925           uibits );
926  }
927
928  printf( "[Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]  ", dYPSNR, dUPSNR, dVPSNR );
929  printf ("[ET %5.0f ] ", dEncTime );
930
931  for (Int iRefList = 0; iRefList < 2; iRefList++)
932  {
933    printf ("[L%d ", iRefList);
934    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
935    {
936      if( pcSlice->getViewIdx() != pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) )
937      {
938        printf( "V%d", pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) );
939        if( pcSlice->getPOC() != pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) )
940          printf( "(%d)", pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) );
941        printf( " " );
942      }
943      else
944        printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
945    }
946    printf ("] ");
947  }
948#if DCM_COMB_LIST
949  if(pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0 && !pcSlice->getNoBackPredFlag())
950  {
951    printf ("[LC ");
952    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(REF_PIC_LIST_C); iRefIndex++)
953    {
954      printf ("%d ", pcSlice->getRefPOC((RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex)));
955    }
956    printf ("] ");
957  }
958#endif
959
960  fflush(stdout);
961}
962
963#if DCM_DECODING_REFRESH
964/** Function for deciding the nal_unit_type.
965 * \param uiPOCCurr POC of the current picture
966 * \returns the nal_unit type of the picture
967 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
968 */
969NalUnitType TEncPic::getNalUnitType(UInt uiPOCCurr)
970{
971  if (uiPOCCurr == 0)
972  {
973    return NAL_UNIT_CODED_SLICE_IDR;
974  }
975#if 0
976  if (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0)
977  {
978    if (m_pcCfg->getDecodingRefreshType() == 1)
979    {
980      return NAL_UNIT_CODED_SLICE_CDR;
981    }
982    else if (m_pcCfg->getDecodingRefreshType() == 2)
983    {
984      return NAL_UNIT_CODED_SLICE_IDR;
985    }
986  }
987#endif
988  return NAL_UNIT_CODED_SLICE;
989}
990#endif
991
992#if RVM_VCEGAM10
993Double TEncPic::xCalculateRVM()
994{
995  Double dRVM = 0;
996
997  //if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFrameToBeEncoded() > RVM_VCEGAM10_M * 2 )
998  {
999    // calculate RVM only for lowdelay configurations
1000    std::vector<Double> vRL , vB;
1001    size_t N = m_vRVM_RP.size();
1002    vRL.resize( N );
1003    vB.resize( N );
1004
1005    Int i;
1006    Double dRavg = 0 , dBavg = 0;
1007    vB[RVM_VCEGAM10_M] = 0;
1008    for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ )
1009    {
1010      vRL[i] = 0;
1011      for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ )
1012        vRL[i] += m_vRVM_RP[j];
1013      vRL[i] /= ( 2 * RVM_VCEGAM10_M );
1014      vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i];
1015      dRavg += m_vRVM_RP[i];
1016      dBavg += vB[i];
1017    }
1018
1019    dRavg /= ( N - 2 * RVM_VCEGAM10_M );
1020    dBavg /= ( N - 2 * RVM_VCEGAM10_M );
1021
1022    double dSigamB = 0;
1023    for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ )
1024    {
1025      Double tmp = vB[i] - dBavg;
1026      dSigamB += tmp * tmp;
1027    }
1028    dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) );
1029
1030    double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) );
1031
1032    dRVM = dSigamB / dRavg * f;
1033  }
1034
1035  return( dRVM );
1036}
1037#endif
1038
Note: See TracBrowser for help on using the repository browser.