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 | #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 H_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 | |
---|
156 | public: |
---|
157 | TEncGOP(); |
---|
158 | virtual ~TEncGOP(); |
---|
159 | |
---|
160 | Void create (); |
---|
161 | Void destroy (); |
---|
162 | |
---|
163 | Void init ( TEncTop* pcTEncTop ); |
---|
164 | #if NH_MV |
---|
165 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
166 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
167 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Int iGOPid ); |
---|
168 | #else |
---|
169 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
170 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
171 | #endif |
---|
172 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
173 | |
---|
174 | #if NH_MV |
---|
175 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
176 | Int getLayerId () { return m_layerId; } |
---|
177 | Int getViewId () { return m_viewId; } |
---|
178 | #if NH_3D |
---|
179 | Int getViewIndex () { return m_viewIndex; } |
---|
180 | Bool getIsDepth () { return m_isDepth; } |
---|
181 | #endif |
---|
182 | #endif |
---|
183 | |
---|
184 | Int getGOPSize() { return m_iGopSize; } |
---|
185 | |
---|
186 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
187 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
188 | #if NH_3D_VSO |
---|
189 | Void preLoopFilterPicAll ( TComPic* pcPic, Dist64& ruiDist); |
---|
190 | #else |
---|
191 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
192 | #endif |
---|
193 | |
---|
194 | #if KWU_RC_MADPRED_E0227 |
---|
195 | TEncTop* getEncTop() { return m_pcEncTop; } |
---|
196 | #endif |
---|
197 | |
---|
198 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
199 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
200 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
201 | |
---|
202 | protected: |
---|
203 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
204 | |
---|
205 | protected: |
---|
206 | |
---|
207 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
208 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
209 | |
---|
210 | 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 ); |
---|
211 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
212 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
213 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
214 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
215 | #if NH_3D_VSO |
---|
216 | Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
217 | #else |
---|
218 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
219 | #endif |
---|
220 | Double xCalculateRVM(); |
---|
221 | |
---|
222 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
223 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
224 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
225 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
226 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
227 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
228 | |
---|
229 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
230 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
231 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
232 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
233 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
234 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
235 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
236 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
237 | |
---|
238 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
239 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
240 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
241 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice); |
---|
242 | |
---|
243 | #if NH_MV |
---|
244 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
245 | #endif |
---|
246 | |
---|
247 | |
---|
248 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
249 | };// END CLASS DEFINITION TEncGOP |
---|
250 | |
---|
251 | //! \} |
---|
252 | |
---|
253 | #endif // __TENCGOP__ |
---|
254 | |
---|