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-2016, 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 | |
---|
69 | class TEncTop; |
---|
70 | |
---|
71 | // ==================================================================================================================== |
---|
72 | // Class definition |
---|
73 | // ==================================================================================================================== |
---|
74 | |
---|
75 | class 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 | |
---|
88 | private: |
---|
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 | #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 |
---|
143 | |
---|
144 | #if SVC_EXTENSION |
---|
145 | Int m_pocCraWithoutReset; |
---|
146 | Int m_associatedIrapPocBeforeReset; |
---|
147 | UInt m_layerId; |
---|
148 | TEncTop** m_ppcTEncTop; |
---|
149 | TEncSearch* m_pcPredSearch; ///< encoder search class |
---|
150 | #if CGS_3D_ASYMLUT |
---|
151 | TEnc3DAsymLUT m_Enc3DAsymLUTPicUpdate; |
---|
152 | TEnc3DAsymLUT m_Enc3DAsymLUTPPS; |
---|
153 | TComPicYuv* m_pColorMappedPic; |
---|
154 | |
---|
155 | UChar m_cgsFilterLength; |
---|
156 | UChar m_cgsFilterPhases; |
---|
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]; |
---|
166 | #endif |
---|
167 | Int m_lastPocPeriodId; |
---|
168 | Bool m_noRaslOutputFlag; |
---|
169 | Bool m_prevPicHasEos; |
---|
170 | static Bool m_signalledVPS; |
---|
171 | #endif |
---|
172 | |
---|
173 | public: |
---|
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 (); |
---|
183 | |
---|
184 | Void init ( TEncTop* pcTEncTop ); |
---|
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 ); |
---|
188 | #else |
---|
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 ); |
---|
191 | #endif |
---|
192 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
193 | |
---|
194 | |
---|
195 | Int getGOPSize() { return m_iGopSize; } |
---|
196 | |
---|
197 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
198 | |
---|
199 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
200 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
201 | |
---|
202 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
203 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
204 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
205 | |
---|
206 | #if SVC_EXTENSION |
---|
207 | Void determinePocResetIdc( Int const pocCurr, TComSlice *const slice); |
---|
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; } |
---|
212 | Void updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice); |
---|
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(); } |
---|
220 | #endif |
---|
221 | |
---|
222 | protected: |
---|
223 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
224 | |
---|
225 | protected: |
---|
226 | |
---|
227 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
228 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
229 | |
---|
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 ); |
---|
231 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
232 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
233 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
234 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
235 | |
---|
236 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
237 | |
---|
238 | Double xCalculateRVM(); |
---|
239 | |
---|
240 | Void xWriteAccessUnitDelimiter (AccessUnit &accessUnit, TComSlice *slice); |
---|
241 | |
---|
242 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
243 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
244 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
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); |
---|
248 | |
---|
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 | |
---|
275 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
276 | #if W0038_DB_OPT |
---|
277 | Void applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID ); |
---|
278 | #endif |
---|
279 | |
---|
280 | #if SVC_EXTENSION |
---|
281 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
282 | Void xBuildTileSetsMap(TComPicSym* picSym); |
---|
283 | #endif |
---|
284 | #if CGS_3D_ASYMLUT |
---|
285 | Void xDetermine3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS ); |
---|
286 | Void xDownScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, const BitDepths& bitDepth, const Int posScalingFactorX); |
---|
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); |
---|
290 | Void xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height, Int width, const BitDepths& bitDepth, ComponentID comp ); |
---|
291 | |
---|
292 | Int xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX); |
---|
293 | Void xDestroy2DArray(Int **array2D, Int iPadY, Int iPadX); |
---|
294 | #endif |
---|
295 | Void xCheckLayerReset(TComSlice *slice); |
---|
296 | Void xSetNoRaslOutputFlag(TComSlice *slice); |
---|
297 | Void xSetLayerInitializedFlag(TComSlice *slice); |
---|
298 | #endif //SVC_EXTENSION |
---|
299 | };// END CLASS DEFINITION TEncGOP |
---|
300 | |
---|
301 | //! \} |
---|
302 | |
---|
303 | #endif // __TENCGOP__ |
---|
304 | |
---|