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-2017, 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 | #if EXTENSION_360_VIDEO |
---|
58 | #include "TAppEncHelper360/TExt360EncGop.h" |
---|
59 | #endif |
---|
60 | |
---|
61 | #include "TEncAnalyze.h" |
---|
62 | #include "TEncRateCtrl.h" |
---|
63 | #if KWU_RC_MADPRED_E0227 |
---|
64 | #include "../App/TAppEncoder/TAppEncTop.h" |
---|
65 | #endif |
---|
66 | #include <vector> |
---|
67 | |
---|
68 | //! \ingroup TLibEncoder |
---|
69 | //! \{ |
---|
70 | |
---|
71 | class TEncTop; |
---|
72 | |
---|
73 | // ==================================================================================================================== |
---|
74 | // Class definition |
---|
75 | // ==================================================================================================================== |
---|
76 | |
---|
77 | class TEncGOP |
---|
78 | { |
---|
79 | class DUData |
---|
80 | { |
---|
81 | public: |
---|
82 | DUData() |
---|
83 | :accumBitsDU(0) |
---|
84 | ,accumNalsDU(0) {}; |
---|
85 | |
---|
86 | Int accumBitsDU; |
---|
87 | Int accumNalsDU; |
---|
88 | }; |
---|
89 | |
---|
90 | private: |
---|
91 | |
---|
92 | TEncAnalyze m_gcAnalyzeAll; |
---|
93 | TEncAnalyze m_gcAnalyzeI; |
---|
94 | TEncAnalyze m_gcAnalyzeP; |
---|
95 | TEncAnalyze m_gcAnalyzeB; |
---|
96 | |
---|
97 | TEncAnalyze m_gcAnalyzeAll_in; |
---|
98 | |
---|
99 | #if EXTENSION_360_VIDEO |
---|
100 | TExt360EncGop m_ext360; |
---|
101 | public: |
---|
102 | TExt360EncGop &getExt360Data() { return m_ext360; } |
---|
103 | private: |
---|
104 | #endif |
---|
105 | |
---|
106 | // Data |
---|
107 | Bool m_bLongtermTestPictureHasBeenCoded; |
---|
108 | Bool m_bLongtermTestPictureHasBeenCoded2; |
---|
109 | UInt m_numLongTermRefPicSPS; |
---|
110 | UInt m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
111 | Bool m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
112 | Int m_iLastIDR; |
---|
113 | Int m_iGopSize; |
---|
114 | Int m_iNumPicCoded; |
---|
115 | Bool m_bFirst; |
---|
116 | Int m_iLastRecoveryPicPOC; |
---|
117 | |
---|
118 | // Access channel |
---|
119 | TEncTop* m_pcEncTop; |
---|
120 | TEncCfg* m_pcCfg; |
---|
121 | TEncSlice* m_pcSliceEncoder; |
---|
122 | TComList<TComPic*>* m_pcListPic; |
---|
123 | |
---|
124 | TEncEntropy* m_pcEntropyCoder; |
---|
125 | TEncCavlc* m_pcCavlcCoder; |
---|
126 | TEncSbac* m_pcSbacCoder; |
---|
127 | TEncBinCABAC* m_pcBinCABAC; |
---|
128 | TComLoopFilter* m_pcLoopFilter; |
---|
129 | |
---|
130 | SEIWriter m_seiWriter; |
---|
131 | |
---|
132 | #if NH_MV |
---|
133 | TComPicLists* m_ivPicLists; |
---|
134 | std::vector<TComPic*> m_refPicSetInterLayer0; |
---|
135 | std::vector<TComPic*> m_refPicSetInterLayer1; |
---|
136 | |
---|
137 | Int m_pocLastCoded; |
---|
138 | Int m_layerId; |
---|
139 | Int m_viewId; |
---|
140 | #endif |
---|
141 | #if NH_3D |
---|
142 | Int m_viewIndex; |
---|
143 | Bool m_isDepth; |
---|
144 | |
---|
145 | Int* m_aICEnableCandidate; |
---|
146 | Int* m_aICEnableNum; |
---|
147 | #endif |
---|
148 | //--Adaptive Loop filter |
---|
149 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
150 | TEncRateCtrl* m_pcRateCtrl; |
---|
151 | // indicate sequence first |
---|
152 | Bool m_bSeqFirst; |
---|
153 | |
---|
154 | // clean decoding refresh |
---|
155 | Bool m_bRefreshPending; |
---|
156 | Int m_pocCRA; |
---|
157 | NalUnitType m_associatedIRAPType; |
---|
158 | Int m_associatedIRAPPOC; |
---|
159 | |
---|
160 | std::vector<Int> m_vRVM_RP; |
---|
161 | UInt m_lastBPSEI; |
---|
162 | UInt m_totalCoded; |
---|
163 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
164 | SEIEncoder m_seiEncoder; |
---|
165 | TComPicYuv* m_pcDeblockingTempPicYuv; |
---|
166 | Int m_DBParam[MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS][4]; //[layer_id][0: available; 1: bDBDisabled; 2: Beta Offset Div2; 3: Tc Offset Div2;] |
---|
167 | |
---|
168 | public: |
---|
169 | TEncGOP(); |
---|
170 | virtual ~TEncGOP(); |
---|
171 | |
---|
172 | Void create (); |
---|
173 | Void destroy (); |
---|
174 | |
---|
175 | Void init ( TEncTop* pcTEncTop ); |
---|
176 | #if NH_MV |
---|
177 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
178 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
179 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, const Bool printMSSSIM, Int iGOPid ); |
---|
180 | #else |
---|
181 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
182 | #if JVET_F0064_MSSSIM |
---|
183 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, const Bool printMSSSIM ); |
---|
184 | #else |
---|
185 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
186 | #endif |
---|
187 | #endif |
---|
188 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
189 | |
---|
190 | #if NH_MV |
---|
191 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
192 | Int getLayerId () { return m_layerId; } |
---|
193 | Int getViewId () { return m_viewId; } |
---|
194 | #if NH_3D |
---|
195 | Int getViewIndex () { return m_viewIndex; } |
---|
196 | Bool getIsDepth () { return m_isDepth; } |
---|
197 | #endif |
---|
198 | #endif |
---|
199 | |
---|
200 | Int getGOPSize() { return m_iGopSize; } |
---|
201 | |
---|
202 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
203 | #if JVET_F0064_MSSSIM |
---|
204 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const Bool printMSSSIM, const BitDepths &bitDepths ); |
---|
205 | #else |
---|
206 | |
---|
207 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
208 | #endif |
---|
209 | #if NH_3D_VSO |
---|
210 | Void preLoopFilterPicAll ( TComPic* pcPic, Dist64& ruiDist); |
---|
211 | #else |
---|
212 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
213 | #endif |
---|
214 | |
---|
215 | #if KWU_RC_MADPRED_E0227 |
---|
216 | TEncTop* getEncTop() { return m_pcEncTop; } |
---|
217 | #endif |
---|
218 | |
---|
219 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
220 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
221 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
222 | |
---|
223 | TEncAnalyze& getAnalyzeAllData() { return m_gcAnalyzeAll; } |
---|
224 | TEncAnalyze& getAnalyzeIData() { return m_gcAnalyzeI; } |
---|
225 | TEncAnalyze& getAnalyzePData() { return m_gcAnalyzeP; } |
---|
226 | TEncAnalyze& getAnalyzeBData() { return m_gcAnalyzeB; } |
---|
227 | |
---|
228 | protected: |
---|
229 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
230 | |
---|
231 | protected: |
---|
232 | |
---|
233 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
234 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
235 | |
---|
236 | #if JVET_F0064_MSSSIM |
---|
237 | 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, const Bool printMSSSIM, Double* PSNR_Y ); |
---|
238 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, const Bool printMSSSIM, Double* PSNR_Y ); |
---|
239 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
240 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
241 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, const Bool printMSSSIM, Double* PSNR_Y ); |
---|
242 | Double xCalculateMSSSIM (const Pel *pOrg, const Int orgStride, const Pel* pRec, const Int recStride, const Int width, const Int height, const UInt bitDepth); |
---|
243 | #else |
---|
244 | 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 ); |
---|
245 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Double* PSNR_Y ); |
---|
246 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
247 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
248 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Double* PSNR_Y ); |
---|
249 | #endif |
---|
250 | |
---|
251 | #if NH_3D_VSO |
---|
252 | Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
253 | #else |
---|
254 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
255 | #endif |
---|
256 | Double xCalculateRVM(); |
---|
257 | |
---|
258 | Void xWriteAccessUnitDelimiter (AccessUnit &accessUnit, TComSlice *slice); |
---|
259 | |
---|
260 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
261 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
262 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
263 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
264 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
265 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
266 | |
---|
267 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
268 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
269 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
270 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
271 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
272 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
273 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
274 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
275 | |
---|
276 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
277 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
278 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
279 | #if NH_MV |
---|
280 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice, const Bool bSeqFirst, const Bool bWriteVps ); |
---|
281 | #else |
---|
282 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice, const Bool bSeqFirst ); |
---|
283 | #endif |
---|
284 | |
---|
285 | #if NH_MV |
---|
286 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
287 | #endif |
---|
288 | |
---|
289 | |
---|
290 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
291 | Void applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID ); |
---|
292 | };// END CLASS DEFINITION TEncGOP |
---|
293 | |
---|
294 | //! \} |
---|
295 | |
---|
296 | #endif // __TENCGOP__ |
---|
297 | |
---|