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 | #if KWU_RC_MADPRED_E0227 |
---|
61 | #include "../App/TAppEncoder/TAppEncTop.h" |
---|
62 | #endif |
---|
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 | #if NH_MV |
---|
122 | TComPicLists* m_ivPicLists; |
---|
123 | std::vector<TComPic*> m_refPicSetInterLayer0; |
---|
124 | std::vector<TComPic*> m_refPicSetInterLayer1; |
---|
125 | |
---|
126 | Int m_pocLastCoded; |
---|
127 | Int m_layerId; |
---|
128 | Int m_viewId; |
---|
129 | #if NH_3D |
---|
130 | Int m_viewIndex; |
---|
131 | Bool m_isDepth; |
---|
132 | #endif |
---|
133 | #endif |
---|
134 | #if NH_3D_IC |
---|
135 | Int* m_aICEnableCandidate; |
---|
136 | Int* m_aICEnableNum; |
---|
137 | #endif |
---|
138 | //--Adaptive Loop filter |
---|
139 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
140 | TEncRateCtrl* m_pcRateCtrl; |
---|
141 | // indicate sequence first |
---|
142 | Bool m_bSeqFirst; |
---|
143 | |
---|
144 | // clean decoding refresh |
---|
145 | Bool m_bRefreshPending; |
---|
146 | Int m_pocCRA; |
---|
147 | NalUnitType m_associatedIRAPType; |
---|
148 | Int m_associatedIRAPPOC; |
---|
149 | |
---|
150 | std::vector<Int> m_vRVM_RP; |
---|
151 | UInt m_lastBPSEI; |
---|
152 | UInt m_totalCoded; |
---|
153 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
154 | SEIEncoder m_seiEncoder; |
---|
155 | #if W0038_DB_OPT |
---|
156 | TComPicYuv* m_pcDeblockingTempPicYuv; |
---|
157 | Int m_DBParam[MAX_ENCODER_DEBLOCKING_QUALITY_LAYERS][4]; //[layer_id][0: available; 1: bDBDisabled; 2: Beta Offset Div2; 3: Tc Offset Div2;] |
---|
158 | #endif |
---|
159 | |
---|
160 | public: |
---|
161 | TEncGOP(); |
---|
162 | virtual ~TEncGOP(); |
---|
163 | |
---|
164 | Void create (); |
---|
165 | Void destroy (); |
---|
166 | |
---|
167 | Void init ( TEncTop* pcTEncTop ); |
---|
168 | #if NH_MV |
---|
169 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
170 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
171 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Int iGOPid ); |
---|
172 | #else |
---|
173 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
174 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
175 | #endif |
---|
176 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
177 | |
---|
178 | #if NH_MV |
---|
179 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
180 | Int getLayerId () { return m_layerId; } |
---|
181 | Int getViewId () { return m_viewId; } |
---|
182 | #if NH_3D |
---|
183 | Int getViewIndex () { return m_viewIndex; } |
---|
184 | Bool getIsDepth () { return m_isDepth; } |
---|
185 | #endif |
---|
186 | #endif |
---|
187 | |
---|
188 | Int getGOPSize() { return m_iGopSize; } |
---|
189 | |
---|
190 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
191 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
192 | #if NH_3D_VSO |
---|
193 | Void preLoopFilterPicAll ( TComPic* pcPic, Dist64& ruiDist); |
---|
194 | #else |
---|
195 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
196 | #endif |
---|
197 | |
---|
198 | #if KWU_RC_MADPRED_E0227 |
---|
199 | TEncTop* getEncTop() { return m_pcEncTop; } |
---|
200 | #endif |
---|
201 | |
---|
202 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
203 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
204 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
205 | |
---|
206 | protected: |
---|
207 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
208 | |
---|
209 | protected: |
---|
210 | |
---|
211 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
212 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
213 | |
---|
214 | 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 ); |
---|
215 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
216 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
217 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
218 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
219 | #if NH_3D_VSO |
---|
220 | Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
221 | #else |
---|
222 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
223 | #endif |
---|
224 | Double xCalculateRVM(); |
---|
225 | |
---|
226 | Void xWriteAccessUnitDelimiter (AccessUnit &accessUnit, TComSlice *slice); |
---|
227 | |
---|
228 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
229 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
230 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
231 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
232 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
233 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
234 | |
---|
235 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
236 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
237 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
238 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
239 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
240 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
241 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
242 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
243 | |
---|
244 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
245 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
246 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
247 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice); |
---|
248 | |
---|
249 | #if NH_MV |
---|
250 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
251 | #endif |
---|
252 | |
---|
253 | |
---|
254 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
255 | #if W0038_DB_OPT |
---|
256 | Void applyDeblockingFilterParameterSelection( TComPic* pcPic, const UInt numSlices, const Int gopID ); |
---|
257 | #endif |
---|
258 | };// END CLASS DEFINITION TEncGOP |
---|
259 | |
---|
260 | //! \} |
---|
261 | |
---|
262 | #endif // __TENCGOP__ |
---|
263 | |
---|