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 | #if CGS_3D_ASYMLUT |
---|
58 | #include "TEnc3DAsymLUT.h" |
---|
59 | #endif |
---|
60 | |
---|
61 | #include "TEncAnalyze.h" |
---|
62 | #include "TEncRateCtrl.h" |
---|
63 | #include <vector> |
---|
64 | |
---|
65 | //! \ingroup TLibEncoder |
---|
66 | //! \{ |
---|
67 | |
---|
68 | class TEncTop; |
---|
69 | |
---|
70 | // ==================================================================================================================== |
---|
71 | // Class definition |
---|
72 | // ==================================================================================================================== |
---|
73 | |
---|
74 | class TEncGOP |
---|
75 | { |
---|
76 | class DUData |
---|
77 | { |
---|
78 | public: |
---|
79 | DUData() |
---|
80 | :accumBitsDU(0) |
---|
81 | ,accumNalsDU(0) {}; |
---|
82 | |
---|
83 | Int accumBitsDU; |
---|
84 | Int accumNalsDU; |
---|
85 | }; |
---|
86 | |
---|
87 | private: |
---|
88 | |
---|
89 | TEncAnalyze m_gcAnalyzeAll; |
---|
90 | TEncAnalyze m_gcAnalyzeI; |
---|
91 | TEncAnalyze m_gcAnalyzeP; |
---|
92 | TEncAnalyze m_gcAnalyzeB; |
---|
93 | |
---|
94 | TEncAnalyze m_gcAnalyzeAll_in; |
---|
95 | // Data |
---|
96 | Bool m_bLongtermTestPictureHasBeenCoded; |
---|
97 | Bool m_bLongtermTestPictureHasBeenCoded2; |
---|
98 | UInt m_numLongTermRefPicSPS; |
---|
99 | UInt m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
100 | Bool m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
101 | Int m_iLastIDR; |
---|
102 | Int m_iGopSize; |
---|
103 | Int m_iNumPicCoded; |
---|
104 | Bool m_bFirst; |
---|
105 | Int m_iLastRecoveryPicPOC; |
---|
106 | |
---|
107 | // Access channel |
---|
108 | TEncTop* m_pcEncTop; |
---|
109 | TEncCfg* m_pcCfg; |
---|
110 | TEncSlice* m_pcSliceEncoder; |
---|
111 | TComList<TComPic*>* m_pcListPic; |
---|
112 | |
---|
113 | TEncEntropy* m_pcEntropyCoder; |
---|
114 | TEncCavlc* m_pcCavlcCoder; |
---|
115 | TEncSbac* m_pcSbacCoder; |
---|
116 | TEncBinCABAC* m_pcBinCABAC; |
---|
117 | TComLoopFilter* m_pcLoopFilter; |
---|
118 | |
---|
119 | SEIWriter m_seiWriter; |
---|
120 | |
---|
121 | //--Adaptive Loop filter |
---|
122 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
123 | TEncRateCtrl* m_pcRateCtrl; |
---|
124 | // indicate sequence first |
---|
125 | Bool m_bSeqFirst; |
---|
126 | |
---|
127 | // clean decoding refresh |
---|
128 | Bool m_bRefreshPending; |
---|
129 | Int m_pocCRA; |
---|
130 | NalUnitType m_associatedIRAPType; |
---|
131 | Int m_associatedIRAPPOC; |
---|
132 | |
---|
133 | std::vector<Int> m_vRVM_RP; |
---|
134 | UInt m_lastBPSEI; |
---|
135 | UInt m_totalCoded; |
---|
136 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
137 | SEIEncoder m_seiEncoder; |
---|
138 | |
---|
139 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
140 | TComSEIColourRemappingInfo m_seiColourRemappingInfo; |
---|
141 | #endif |
---|
142 | #if SVC_EXTENSION |
---|
143 | Int m_pocCraWithoutReset; |
---|
144 | Int m_associatedIrapPocBeforeReset; |
---|
145 | UInt m_layerId; |
---|
146 | TEncTop** m_ppcTEncTop; |
---|
147 | TEncSearch* m_pcPredSearch; ///< encoder search class |
---|
148 | #if CGS_3D_ASYMLUT |
---|
149 | TEnc3DAsymLUT m_Enc3DAsymLUTPicUpdate; |
---|
150 | TEnc3DAsymLUT m_Enc3DAsymLUTPPS; |
---|
151 | TComPicYuv* m_pColorMappedPic; |
---|
152 | |
---|
153 | Int m_iTap; |
---|
154 | const Int (*m_phase_filter)[13]; |
---|
155 | const Int (*m_phase_filter_luma)[13]; |
---|
156 | const Int (*m_phase_filter_chroma)[13]; |
---|
157 | Int m_iM, m_iN; |
---|
158 | static const Int m_phase_filter_0_t0[4][13]; |
---|
159 | static const Int m_phase_filter_0_t1[4][13]; |
---|
160 | static const Int m_phase_filter_0_t1_chroma[4][13]; |
---|
161 | static const Int m_phase_filter_1[8][13]; |
---|
162 | Int **m_temp; |
---|
163 | #endif |
---|
164 | Int m_lastPocPeriodId; |
---|
165 | Bool m_noRaslOutputFlag; |
---|
166 | Bool m_prevPicHasEos; |
---|
167 | static Bool m_signalledVPS; |
---|
168 | #endif |
---|
169 | |
---|
170 | public: |
---|
171 | TEncGOP(); |
---|
172 | virtual ~TEncGOP(); |
---|
173 | |
---|
174 | #if SVC_EXTENSION |
---|
175 | Void create ( UInt layerId ); |
---|
176 | #else |
---|
177 | Void create (); |
---|
178 | #endif |
---|
179 | Void destroy (); |
---|
180 | |
---|
181 | Void init ( TEncTop* pcTEncTop ); |
---|
182 | #if SVC_EXTENSION |
---|
183 | Void compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
184 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
185 | #else |
---|
186 | Void compressGOP ( 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 | #endif |
---|
189 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
190 | |
---|
191 | |
---|
192 | Int getGOPSize() { return m_iGopSize; } |
---|
193 | |
---|
194 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
195 | |
---|
196 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
197 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
198 | |
---|
199 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
200 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
201 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
202 | |
---|
203 | #if SVC_EXTENSION |
---|
204 | Void determinePocResetIdc( Int const pocCurr, TComSlice *const slice); |
---|
205 | Int getIntraRefreshInterval() { return m_pcCfg->getIntraPeriod(); } |
---|
206 | Int getIntraRefreshType() { return m_pcCfg->getDecodingRefreshType(); } |
---|
207 | Int getLastPocPeriodId() { return m_lastPocPeriodId; } |
---|
208 | Void setLastPocPeriodId(Int x) { m_lastPocPeriodId = x; } |
---|
209 | Void updatePocValuesOfPics( Int const pocCurr, TComSlice *const slice); |
---|
210 | |
---|
211 | TEncAnalyze* getAnalyzeAll() { return &m_gcAnalyzeAll; } |
---|
212 | TEncAnalyze* getAnalyzeI() { return &m_gcAnalyzeI; } |
---|
213 | TEncAnalyze* getAnalyzeP() { return &m_gcAnalyzeP; } |
---|
214 | TEncAnalyze* getAnalyzeB() { return &m_gcAnalyzeB; } |
---|
215 | TEncAnalyze* getAnalyzeAllin() { return &m_gcAnalyzeAll_in; } |
---|
216 | Double calculateRVM() { return xCalculateRVM(); } |
---|
217 | #endif |
---|
218 | |
---|
219 | protected: |
---|
220 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
221 | |
---|
222 | protected: |
---|
223 | |
---|
224 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
225 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
226 | |
---|
227 | 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 ); |
---|
228 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
229 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
230 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
231 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
232 | |
---|
233 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
234 | |
---|
235 | Double xCalculateRVM(); |
---|
236 | |
---|
237 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
238 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
239 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
240 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
241 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
242 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
243 | |
---|
244 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
245 | #if O0164_MULTI_LAYER_HRD |
---|
246 | 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); |
---|
247 | 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); |
---|
248 | #else |
---|
249 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
250 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
251 | #endif |
---|
252 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
253 | #if O0164_MULTI_LAYER_HRD |
---|
254 | 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); |
---|
255 | 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); |
---|
256 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComVPS *vps, const TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL); |
---|
257 | 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); |
---|
258 | #else |
---|
259 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
260 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
261 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
262 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
263 | #endif |
---|
264 | |
---|
265 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
266 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
267 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
268 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice); |
---|
269 | |
---|
270 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
271 | |
---|
272 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
273 | TComSEIColourRemappingInfo* xGetSEIColourRemappingInfo() { return &m_seiColourRemappingInfo; } |
---|
274 | Void setCRISEIFile( Char* pch ) { m_seiColourRemappingInfo.m_colourRemapSEIFile = pch; } |
---|
275 | |
---|
276 | Void freeColourCRI(); |
---|
277 | Int readingCRIparameters(); |
---|
278 | Void xCheckParameter(); |
---|
279 | #endif |
---|
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 xDetermin3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS ); |
---|
286 | Void downScalePic( TComPicYuv* pcYuvSrc, TComPicYuv* pcYuvDest, BitDepths& bitDepth); |
---|
287 | Void downScaleComponent2x2( 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 initDs(Int iWidth, Int iHeight, Int iType); |
---|
290 | Void filterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, Int plane ); |
---|
291 | |
---|
292 | Int get_mem2DintWithPad(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX); |
---|
293 | Void free_mem2DintWithPad(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 | |
---|