source: 3DVCSoftware/branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp @ 41

Last change on this file since 41 was 41, checked in by poznan-univ, 13 years ago

Adjustment for FlexCO, and high-level syntax improvement.

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