source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h @ 1598

Last change on this file since 1598 was 1572, checked in by seregin, 9 years ago

port rev 4752

  • Property svn:eol-style set to native
File size: 14.9 KB
RevLine 
[313]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
[1029]4 * granted under this license.
[313]5 *
[1549]6 * Copyright (c) 2010-2016, ITU/ISO/IEC
[313]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncGOP.h
35    \brief    GOP encoder class (header)
36*/
37
38#ifndef __TENCGOP__
39#define __TENCGOP__
40
41#include <list>
42
43#include <stdlib.h>
44
45#include "TLibCommon/TComList.h"
46#include "TLibCommon/TComPic.h"
47#include "TLibCommon/TComBitCounter.h"
48#include "TLibCommon/TComLoopFilter.h"
49#include "TLibCommon/AccessUnit.h"
50#include "TEncSampleAdaptiveOffset.h"
51#include "TEncSlice.h"
52#include "TEncEntropy.h"
53#include "TEncCavlc.h"
54#include "TEncSbac.h"
55#include "SEIwrite.h"
[1273]56#include "SEIEncoder.h"
[313]57
58#include "TEncAnalyze.h"
59#include "TEncRateCtrl.h"
60#include <vector>
61
[1415]62#if CGS_3D_ASYMLUT
63#include "TEnc3DAsymLUT.h"
64#endif
65
[313]66//! \ingroup TLibEncoder
67//! \{
68
69class TEncTop;
70
71// ====================================================================================================================
72// Class definition
73// ====================================================================================================================
74
75class TEncGOP
76{
[1273]77  class DUData
78  {
79  public:
80    DUData()
81    :accumBitsDU(0)
82    ,accumNalsDU(0) {};
83
84    Int accumBitsDU;
85    Int accumNalsDU;
86  };
87
[313]88private:
[1292]89
90  TEncAnalyze             m_gcAnalyzeAll;
91  TEncAnalyze             m_gcAnalyzeI;
92  TEncAnalyze             m_gcAnalyzeP;
93  TEncAnalyze             m_gcAnalyzeB;
94
95  TEncAnalyze             m_gcAnalyzeAll_in;
[313]96  //  Data
97  Bool                    m_bLongtermTestPictureHasBeenCoded;
98  Bool                    m_bLongtermTestPictureHasBeenCoded2;
[1029]99  UInt                    m_numLongTermRefPicSPS;
100  UInt                    m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS];
101  Bool                    m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS];
[313]102  Int                     m_iLastIDR;
103  Int                     m_iGopSize;
104  Int                     m_iNumPicCoded;
105  Bool                    m_bFirst;
[713]106  Int                     m_iLastRecoveryPicPOC;
[1029]107
[313]108  //  Access channel
109  TEncTop*                m_pcEncTop;
110  TEncCfg*                m_pcCfg;
111  TEncSlice*              m_pcSliceEncoder;
112  TComList<TComPic*>*     m_pcListPic;
[1029]113
[313]114  TEncEntropy*            m_pcEntropyCoder;
115  TEncCavlc*              m_pcCavlcCoder;
116  TEncSbac*               m_pcSbacCoder;
117  TEncBinCABAC*           m_pcBinCABAC;
118  TComLoopFilter*         m_pcLoopFilter;
119
120  SEIWriter               m_seiWriter;
[1029]121
[313]122  //--Adaptive Loop filter
123  TEncSampleAdaptiveOffset*  m_pcSAO;
124  TEncRateCtrl*           m_pcRateCtrl;
125  // indicate sequence first
126  Bool                    m_bSeqFirst;
[1029]127
[313]128  // clean decoding refresh
129  Bool                    m_bRefreshPending;
130  Int                     m_pocCRA;
[595]131  NalUnitType             m_associatedIRAPType;
132  Int                     m_associatedIRAPPOC;
[313]133
134  std::vector<Int> m_vRVM_RP;
135  UInt                    m_lastBPSEI;
136  UInt                    m_totalCoded;
137  Bool                    m_bufferingPeriodSEIPresentInAU;
[1273]138  SEIEncoder              m_seiEncoder;
[1545]139#if W0038_DB_OPT
140  TComPicYuv*             m_pcDeblockingTempPicYuv;
141  Int                     m_DBParam[MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS][4];   //[layer_id][0: available; 1: bDBDisabled; 2: Beta Offset Div2; 3: Tc Offset Div2;]
142#endif
[595]143
[1209]144#if SVC_EXTENSION
[1029]145  Int                     m_pocCraWithoutReset;
146  Int                     m_associatedIrapPocBeforeReset;
[595]147  UInt                    m_layerId;     
148  TEncTop**               m_ppcTEncTop;
149  TEncSearch*             m_pcPredSearch;                       ///< encoder search class
[1212]150#if CGS_3D_ASYMLUT
[713]151  TEnc3DAsymLUT           m_Enc3DAsymLUTPicUpdate;
152  TEnc3DAsymLUT           m_Enc3DAsymLUTPPS;
153  TComPicYuv*             m_pColorMappedPic;
154
[1442]155  UChar                   m_cgsFilterLength;
156  UChar                   m_cgsFilterPhases;
[1432]157  Int                     m_iN;
158  Int                   **m_temp;
159  const Pel             (*m_phaseFilter)[CGS_FILTER_LENGTH];
160  const Pel             (*m_phaseFilterLuma)[CGS_FILTER_LENGTH];
161  const Pel             (*m_phaseFilterChroma)[CGS_FILTER_LENGTH];
162  static const Pel        m_phaseFilter0T0[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
163  static const Pel        m_phaseFilter0T1[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
164  static const Pel        m_phaseFilter0T1Chroma[CGS_FILTER_PHASES_2X][CGS_FILTER_LENGTH];
165  static const Pel        m_phaseFilter1[CGS_FILTER_PHASES_1X][CGS_FILTER_LENGTH];
[595]166#endif
[1432]167  Int                     m_lastPocPeriodId;
168  Bool                    m_noRaslOutputFlag;
169  Bool                    m_prevPicHasEos;
170  static Bool             m_signalledVPS;
[815]171#endif
[595]172 
[313]173public:
174  TEncGOP();
175  virtual ~TEncGOP();
176 
177#if SVC_EXTENSION
178  Void  create      ( UInt layerId );
179#else
180  Void  create      ();
181#endif
182  Void  destroy     ();
[1029]183
[313]184  Void  init        ( TEncTop* pcTEncTop );
[1029]185#if SVC_EXTENSION 
186  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec,
187                      std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
[313]188#else
[1029]189  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec,
190                      std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE );
[313]191#endif
[1029]192  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect);
[313]193
[1029]194
[313]195  Int   getGOPSize()          { return  m_iGopSize;  }
[1029]196
[313]197  TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
[1307]198
[1289]199  Void  printOutSummary      ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths );
[1029]200  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist );
201
[313]202  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
[595]203  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField );
[313]204  Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& );
[1029]205
[1209]206#if SVC_EXTENSION
[1029]207  Void  determinePocResetIdc( Int const pocCurr, TComSlice *const slice);
[1292]208  Int   getIntraRefreshInterval()   { return m_pcCfg->getIntraPeriod(); }
209  Int   getIntraRefreshType()       { return m_pcCfg->getDecodingRefreshType(); } 
210  Int   getLastPocPeriodId()        { return m_lastPocPeriodId; }
211  Void  setLastPocPeriodId(Int x)   { m_lastPocPeriodId = x;    }
[1029]212  Void  updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice);
[1292]213
214  TEncAnalyze* getAnalyzeAll()      { return &m_gcAnalyzeAll;  }
215  TEncAnalyze* getAnalyzeI()        { return &m_gcAnalyzeI;    }
216  TEncAnalyze* getAnalyzeP()        { return &m_gcAnalyzeP;    }
217  TEncAnalyze* getAnalyzeB()        { return &m_gcAnalyzeB;    }
218  TEncAnalyze* getAnalyzeAllin()    { return &m_gcAnalyzeAll_in; }
219  Double       calculateRVM()       { return xCalculateRVM();    }
[1029]220#endif
221
[313]222protected:
223  TEncRateCtrl* getRateCtrl()       { return m_pcRateCtrl;  }
224
225protected:
[1029]226
[1307]227  Void  xInitGOP          ( Int iPOCLast, Int iNumPicRcvd, Bool isField );
[1029]228  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
229
[1572]230  Void  xCalculateAddPSNRs         ( const Bool isField, const Bool isFieldTopFieldFirst, const Int iGOPid, TComPic* pcPic, const AccessUnit&accessUnit, TComList<TComPic*> &rcListPic, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Double* PSNR_Y );
231  Void  xCalculateAddPSNR          ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Double* PSNR_Y );
[1029]232  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField,
233                                     TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField,
[1572]234                                     const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Double* PSNR_Y );
[1029]235
[1287]236  UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths);
[313]237
238  Double xCalculateRVM();
239
[1415]240  Void xWriteAccessUnitDelimiter (AccessUnit &accessUnit, TComSlice *slice);
241
[1273]242  Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps);
243  Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice);
[1307]244  Void xCreatePictureTimingSEI  (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData);
[1273]245  Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData);
246  Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps);
247  Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI);
[313]248
[1273]249  Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages);
250#if O0164_MULTI_LAYER_HRD
251  Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
252  Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
253#else
254  Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps);
255  Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps);
256#endif
257  Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages);
258#if O0164_MULTI_LAYER_HRD
259  Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, Bool testWrite, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
260  Void xWriteLeadingSEIMessages  (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, std::deque<DUData> &duData, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
261  Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
262  Void xWriteDuSEIMessages       (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *sps, const TComSPS *vps, std::deque<DUData> &duData, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
263#else
264  Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite);
265  Void xWriteLeadingSEIMessages  (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData);
266  Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps);
267  Void xWriteDuSEIMessages       (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData);
268#endif
269
270  Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps);
271  Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps);
272  Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps);
273  Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice);
274
[1235]275  Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices );
[1545]276#if W0038_DB_OPT
277  Void applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID );
278#endif
[595]279
280#if SVC_EXTENSION
[442]281#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
282  Void xBuildTileSetsMap(TComPicSym* picSym);
283#endif
[1212]284#if CGS_3D_ASYMLUT
[1429]285  Void xDetermine3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS );
[1502]286  Void xDownScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, const BitDepths& bitDepth, const Int posScalingFactorX);
[1432]287  Void xDownScaleComponent2x2( const Pel* pSrc, Pel* pDest, const Int iSrcStride, const Int iDestStride, const Int iSrcWidth, const Int iSrcHeight, const Int inputBitDepth, const Int outputBitDepth );
288  inline Short xClip( Short x, Int bitdepth );
289  Void xInitDs( const Int iWidth, const Int iHeight, const Bool allIntra, const Int posScalingFactorX);
[1502]290  Void xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height, Int width, const BitDepths& bitDepth, ComponentID comp );
[713]291
[1432]292  Int  xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
293  Void xDestroy2DArray(Int **array2D, Int iPadY, Int iPadX);
[713]294#endif
[978]295  Void xCheckLayerReset(TComSlice *slice);
296  Void xSetNoRaslOutputFlag(TComSlice *slice);
297  Void xSetLayerInitializedFlag(TComSlice *slice);
[595]298#endif //SVC_EXTENSION
[313]299};// END CLASS DEFINITION TEncGOP
300
301//! \}
302
303#endif // __TENCGOP__
304
Note: See TracBrowser for help on using the repository browser.