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

Last change on this file since 1497 was 1460, checked in by seregin, 9 years ago

port rev 4594

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