source: 3DVCSoftware/branches/0.2-HHI/source/Lib/TLibEncoder/TEncGOP.cpp @ 1417

Last change on this file since 1417 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 36.1 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        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
642        m_pcEntropyCoder->setBitstream(&seiBs);
643        m_pcEntropyCoder->encodeSEI(sei_recon_picture_digest);
644        /* and trailing bits */
645        seiBs.write(1, 1);
646        seiBs.writeAlignZero();
647        seiBs.flushBuffer();
648        seiBs.convertRBSPToPayload(0);
649
650        /* append the SEI message after any SPS/PPS */
651        /* the following loop is a work around current limitations in
652         * TComBitstream that won't be fixed before HM-3.0 */
653        UChar *seiData = reinterpret_cast<UChar *>(seiBs.getStartStream());
654        for (Int i = 0; i < seiBs.getNumberOfWrittenBits()/8; i++)
655        {
656          bs_SPS_PPS_SEI.write(seiData[i], 8);
657        }
658        bs_SPS_PPS_SEI.write(1, 32);
659        seiBs.destroy();
660      }
661
662      /* insert the bs_SPS_PPS_SEI before the pcBitstreamOut */
663      bs_SPS_PPS_SEI.flushBuffer();
664      pcBitstreamOut->insertAt(bs_SPS_PPS_SEI, 0);
665
666      bs_SPS_PPS_SEI.destroy();
667      pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
668
669      pcPic->setReconMark   ( true );
670
671}
672
673Void TEncPic::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits )
674{
675  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
676  Bool bCalcDist = false;
677
678  m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), m_pcCfg->getLoopFilterAlphaC0Offget(), m_pcCfg->getLoopFilterBetaOffget());
679  m_pcLoopFilter->loopFilterPic( pcPic );
680
681  m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice );
682  m_pcEntropyCoder->resetEntropy    ();
683  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
684
685  // Adaptive Loop filter
686  if( pcSlice->getSPS()->getUseALF() )
687  {
688    ALFParam cAlfParam;
689#if TSB_ALF_HEADER
690    m_pcAdaptiveLoopFilter->setNumCUsInFrame(pcPic);
691#endif
692    m_pcAdaptiveLoopFilter->allocALFParam(&cAlfParam);
693
694    m_pcAdaptiveLoopFilter->startALFEnc(pcPic, m_pcEntropyCoder);
695
696    UInt uiMaxAlfCtrlDepth;
697    m_pcAdaptiveLoopFilter->ALFProcess(&cAlfParam, pcSlice->getLambda(), ruiDist, ruiBits, uiMaxAlfCtrlDepth );
698    m_pcAdaptiveLoopFilter->endALFEnc();
699    m_pcAdaptiveLoopFilter->freeALFParam(&cAlfParam);
700  }
701
702  m_pcEntropyCoder->resetEntropy    ();
703  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
704
705  if (!bCalcDist)
706    ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec());
707}
708
709// ====================================================================================================================
710// Protected member functions
711// ====================================================================================================================
712
713UInt64 TEncPic::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1)
714{
715  Int     x, y;
716  Pel*  pSrc0   = pcPic0 ->getLumaAddr();
717  Pel*  pSrc1   = pcPic1 ->getLumaAddr();
718#if IBDI_DISTORTION
719  Int  iShift = g_uiBitIncrement;
720  Int  iOffset = 1<<(g_uiBitIncrement-1);
721#else
722  UInt  uiShift = g_uiBitIncrement<<1;
723#endif
724  Int   iTemp;
725
726  Int   iStride = pcPic0->getStride();
727  Int   iWidth  = pcPic0->getWidth();
728  Int   iHeight = pcPic0->getHeight();
729
730  UInt64  uiTotalDiff = 0;
731
732  for( y = 0; y < iHeight; y++ )
733  {
734    for( x = 0; x < iWidth; x++ )
735    {
736#if IBDI_DISTORTION
737      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
738#else
739      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
740#endif
741    }
742    pSrc0 += iStride;
743    pSrc1 += iStride;
744  }
745
746  iHeight >>= 1;
747  iWidth  >>= 1;
748  iStride >>= 1;
749
750  pSrc0  = pcPic0->getCbAddr();
751  pSrc1  = pcPic1->getCbAddr();
752
753  for( y = 0; y < iHeight; y++ )
754  {
755    for( x = 0; x < iWidth; x++ )
756    {
757#if IBDI_DISTORTION
758      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
759#else
760      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
761#endif
762    }
763    pSrc0 += iStride;
764    pSrc1 += iStride;
765  }
766
767  pSrc0  = pcPic0->getCrAddr();
768  pSrc1  = pcPic1->getCrAddr();
769
770  for( y = 0; y < iHeight; y++ )
771  {
772    for( x = 0; x < iWidth; x++ )
773    {
774#if IBDI_DISTORTION
775      iTemp = ((pSrc0[x]+iOffset)>>iShift) - ((pSrc1[x]+iOffset)>>iShift); uiTotalDiff += iTemp * iTemp;
776#else
777      iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift;
778#endif
779    }
780    pSrc0 += iStride;
781    pSrc1 += iStride;
782  }
783
784  return uiTotalDiff;
785}
786
787Void TEncPic::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, UInt uibits, Double dEncTime )
788{
789  Int     x, y;
790  UInt64 uiSSDY  = 0;
791  UInt64 uiSSDU  = 0;
792  UInt64 uiSSDV  = 0;
793
794  Double  dYPSNR  = 0.0;
795  Double  dUPSNR  = 0.0;
796  Double  dVPSNR  = 0.0;
797
798  //===== calculate PSNR =====
799  Pel*  pOrg    = pcPic ->getPicYuvOrg()->getLumaAddr();
800  Pel*  pRec    = pcPicD->getLumaAddr();
801  Int   iStride = pcPicD->getStride();
802
803  Int   iWidth;
804  Int   iHeight;
805
806  iWidth  = pcPicD->getWidth () - m_pcEncTop->getPad(0);
807  iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1);
808
809  Int   iSize   = iWidth*iHeight;
810
811  UInt   maxval = 255 * (1<<(g_uiBitDepth + g_uiBitIncrement -8));
812  Double fRefValueY = (double) maxval * maxval * iSize;
813  Double fRefValueC = fRefValueY / 4.0;
814
815  for( y = 0; y < iHeight; y++ )
816  {
817    for( x = 0; x < iWidth; x++ )
818    {
819      Int iDiff = (Int)( pOrg[x] - pRec[x] );
820      uiSSDY   += iDiff * iDiff;
821    }
822    pOrg += iStride;
823    pRec += iStride;
824  }
825
826#if HHI_VSO
827  if ( m_pcRdCost->getUseRenModel() )
828  {
829    TRenModel*  pcRenModel = m_pcEncTop->getEncTop()->getRenModel();
830    Int64 iDistVSOY, iDistVSOU, iDistVSOV;
831    pcRenModel->getTotalSSE( iDistVSOY, iDistVSOU, iDistVSOV );
832    dYPSNR = ( iDistVSOY ? 10.0 * log10( fRefValueY / (Double) iDistVSOY ) : 99.99 );
833    dUPSNR = ( iDistVSOU ? 10.0 * log10( fRefValueC / (Double) iDistVSOU ) : 99.99 );
834    dVPSNR = ( iDistVSOV ? 10.0 * log10( fRefValueC / (Double) iDistVSOV ) : 99.99 );
835  }
836  else
837#endif
838  {
839  iHeight >>= 1;
840  iWidth  >>= 1;
841  iStride >>= 1;
842  pOrg  = pcPic ->getPicYuvOrg()->getCbAddr();
843  pRec  = pcPicD->getCbAddr();
844
845  for( y = 0; y < iHeight; y++ )
846  {
847    for( x = 0; x < iWidth; x++ )
848    {
849      Int iDiff = (Int)( pOrg[x] - pRec[x] );
850      uiSSDU   += iDiff * iDiff;
851    }
852    pOrg += iStride;
853    pRec += iStride;
854  }
855
856  pOrg  = pcPic ->getPicYuvOrg()->getCrAddr();
857  pRec  = pcPicD->getCrAddr();
858
859  for( y = 0; y < iHeight; y++ )
860  {
861    for( x = 0; x < iWidth; x++ )
862    {
863      Int iDiff = (Int)( pOrg[x] - pRec[x] );
864      uiSSDV   += iDiff * iDiff;
865    }
866    pOrg += iStride;
867    pRec += iStride;
868  }
869  dYPSNR            = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 );
870  dUPSNR            = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 );
871  dVPSNR            = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 );
872  }
873  // fix: total bits should consider slice size bits (32bit)
874  uibits += 32;
875
876#if RVM_VCEGAM10
877  m_vRVM_RP.push_back( uibits );
878#endif
879
880  //===== add PSNR =====
881  m_pcEncTop->m_cAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
882  TComSlice*  pcSlice = pcPic->getSlice(0);
883  if (pcSlice->isIntra())
884  {
885    m_pcEncTop->m_cAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
886  }
887  if (pcSlice->isInterP())
888  {
889    m_pcEncTop->m_cAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
890  }
891  if (pcSlice->isInterB())
892  {
893    m_pcEncTop->m_cAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
894  }
895  if(pcPic->getViewIdx()!=-1)
896  {
897    if(! m_pcEncTop->isDepthCoder())
898    {
899      printf("\nView \t\t%2d\t POC %4d ( %c-SLICE, QP %d ) %10d bits ",
900      pcSlice->getViewIdx(),
901      pcSlice->getPOC(),
902      pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
903      pcSlice->getSliceQp(),
904      uibits );
905    }
906    else
907    {
908      printf("\nDepth View \t%2d\t POC %4d ( %c-SLICE, QP %d ) %10d bits ",
909            pcSlice->getViewIdx(),
910            pcSlice->getPOC(),
911            pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
912            pcSlice->getSliceQp(),
913            uibits );
914    }
915  }
916  else
917  {
918    printf("\nPOC %4d ( %c-SLICE, QP %d ) %10d bits ",
919           pcSlice->getPOC(),
920           pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B',
921           pcSlice->getSliceQp(),
922           uibits );
923  }
924
925  printf( "[Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]  ", dYPSNR, dUPSNR, dVPSNR );
926  printf ("[ET %5.0f ] ", dEncTime );
927
928  for (Int iRefList = 0; iRefList < 2; iRefList++)
929  {
930    printf ("[L%d ", iRefList);
931    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
932    {
933      if( pcSlice->getViewIdx() != pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) )
934      {
935        printf( "V%d", pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) );
936        if( pcSlice->getPOC() != pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) )
937          printf( "(%d)", pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) );
938        printf( " " );
939      }
940      else
941        printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
942    }
943    printf ("] ");
944  }
945#if DCM_COMB_LIST
946  if(pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0 && !pcSlice->getNoBackPredFlag())
947  {
948    printf ("[LC ");
949    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(REF_PIC_LIST_C); iRefIndex++)
950    {
951      printf ("%d ", pcSlice->getRefPOC((RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex)));
952    }
953    printf ("] ");
954  }
955#endif
956
957  fflush(stdout);
958}
959
960#if DCM_DECODING_REFRESH
961/** Function for deciding the nal_unit_type.
962 * \param uiPOCCurr POC of the current picture
963 * \returns the nal_unit type of the picture
964 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
965 */
966NalUnitType TEncPic::getNalUnitType(UInt uiPOCCurr)
967{
968  if (uiPOCCurr == 0)
969  {
970    return NAL_UNIT_CODED_SLICE_IDR;
971  }
972#if 0
973  if (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0)
974  {
975    if (m_pcCfg->getDecodingRefreshType() == 1)
976    {
977      return NAL_UNIT_CODED_SLICE_CDR;
978    }
979    else if (m_pcCfg->getDecodingRefreshType() == 2)
980    {
981      return NAL_UNIT_CODED_SLICE_IDR;
982    }
983  }
984#endif
985  return NAL_UNIT_CODED_SLICE;
986}
987#endif
988
989#if RVM_VCEGAM10
990Double TEncPic::xCalculateRVM()
991{
992  Double dRVM = 0;
993
994  //if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFrameToBeEncoded() > RVM_VCEGAM10_M * 2 )
995  {
996    // calculate RVM only for lowdelay configurations
997    std::vector<Double> vRL , vB;
998    size_t N = m_vRVM_RP.size();
999    vRL.resize( N );
1000    vB.resize( N );
1001
1002    Int i;
1003    Double dRavg = 0 , dBavg = 0;
1004    vB[RVM_VCEGAM10_M] = 0;
1005    for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ )
1006    {
1007      vRL[i] = 0;
1008      for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ )
1009        vRL[i] += m_vRVM_RP[j];
1010      vRL[i] /= ( 2 * RVM_VCEGAM10_M );
1011      vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i];
1012      dRavg += m_vRVM_RP[i];
1013      dBavg += vB[i];
1014    }
1015
1016    dRavg /= ( N - 2 * RVM_VCEGAM10_M );
1017    dBavg /= ( N - 2 * RVM_VCEGAM10_M );
1018
1019    double dSigamB = 0;
1020    for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ )
1021    {
1022      Double tmp = vB[i] - dBavg;
1023      dSigamB += tmp * tmp;
1024    }
1025    dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) );
1026
1027    double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) );
1028
1029    dRVM = dSigamB / dRavg * f;
1030  }
1031
1032  return( dRVM );
1033}
1034#endif
1035
Note: See TracBrowser for help on using the repository browser.