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 TEncTop.h |
---|
35 | \brief encoder class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TENCTOP__ |
---|
39 | #define __TENCTOP__ |
---|
40 | |
---|
41 | // Include files |
---|
42 | #include "TLibCommon/TComList.h" |
---|
43 | #include "TLibCommon/TComPrediction.h" |
---|
44 | #include "TLibCommon/TComTrQuant.h" |
---|
45 | #include "TLibCommon/TComLoopFilter.h" |
---|
46 | #include "TLibCommon/AccessUnit.h" |
---|
47 | |
---|
48 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
49 | |
---|
50 | #include "TEncCfg.h" |
---|
51 | #include "TEncGOP.h" |
---|
52 | #include "TEncSlice.h" |
---|
53 | #include "TEncEntropy.h" |
---|
54 | #include "TEncCavlc.h" |
---|
55 | #include "TEncSbac.h" |
---|
56 | #include "TEncSearch.h" |
---|
57 | #include "TEncSampleAdaptiveOffset.h" |
---|
58 | #include "TEncPreanalyzer.h" |
---|
59 | #include "TEncRateCtrl.h" |
---|
60 | //! \ingroup TLibEncoder |
---|
61 | //! \{ |
---|
62 | |
---|
63 | // ==================================================================================================================== |
---|
64 | // Class definition |
---|
65 | // ==================================================================================================================== |
---|
66 | |
---|
67 | /// encoder class |
---|
68 | class TEncTop : public TEncCfg |
---|
69 | { |
---|
70 | private: |
---|
71 | // picture |
---|
72 | Int m_iPOCLast; ///< time index (POC) |
---|
73 | Int m_iNumPicRcvd; ///< number of received pictures |
---|
74 | UInt m_uiNumAllPicCoded; ///< number of coded pictures |
---|
75 | TComList<TComPic*> m_cListPic; ///< dynamic list of pictures |
---|
76 | |
---|
77 | // encoder search |
---|
78 | TEncSearch m_cSearch; ///< encoder search class |
---|
79 | //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder |
---|
80 | TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder |
---|
81 | // coding tool |
---|
82 | TComTrQuant m_cTrQuant; ///< transform & quantization class |
---|
83 | TComLoopFilter m_cLoopFilter; ///< deblocking filter class |
---|
84 | TEncSampleAdaptiveOffset m_cEncSAO; ///< sample adaptive offset class |
---|
85 | TEncEntropy m_cEntropyCoder; ///< entropy encoder |
---|
86 | TEncCavlc m_cCavlcCoder; ///< CAVLC encoder |
---|
87 | TEncSbac m_cSbacCoder; ///< SBAC encoder |
---|
88 | TEncBinCABAC m_cBinCoderCABAC; ///< bin coder CABAC |
---|
89 | |
---|
90 | // processing unit |
---|
91 | TEncGOP m_cGOPEncoder; ///< GOP encoder |
---|
92 | TEncSlice m_cSliceEncoder; ///< slice encoder |
---|
93 | TEncCu m_cCuEncoder; ///< CU encoder |
---|
94 | // SPS |
---|
95 | TComSPS m_cSPS; ///< SPS. This is the base value. This is copied to TComPicSym |
---|
96 | TComPPS m_cPPS; ///< PPS. This is the base value. This is copied to TComPicSym |
---|
97 | // RD cost computation |
---|
98 | TComRdCost m_cRdCost; ///< RD cost computation class |
---|
99 | TEncSbac*** m_pppcRDSbacCoder; ///< temporal storage for RD computation |
---|
100 | TEncSbac m_cRDGoOnSbacCoder; ///< going on SBAC model for RD stage |
---|
101 | #if FAST_BIT_EST |
---|
102 | TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
103 | TEncBinCABACCounter m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
104 | #else |
---|
105 | TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
106 | TEncBinCABAC m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
107 | #endif |
---|
108 | |
---|
109 | // quality control |
---|
110 | TEncPreanalyzer m_cPreanalyzer; ///< image characteristics analyzer for TM5-step3-like adaptive QP |
---|
111 | |
---|
112 | TEncRateCtrl m_cRateCtrl; ///< Rate control class |
---|
113 | |
---|
114 | #if SVC_EXTENSION |
---|
115 | static Int m_iSPSIdCnt; ///< next Id number for SPS |
---|
116 | static Int m_iPPSIdCnt; ///< next Id number for PPS |
---|
117 | TEncTop** m_ppcTEncTop; |
---|
118 | TEncTop* getLayerEnc(UInt layerIdx) { return m_ppcTEncTop[layerIdx]; } |
---|
119 | TComPic* m_cIlpPic[MAX_NUM_REF]; ///< Inter layer Prediction picture = upsampled picture |
---|
120 | Bool m_bMFMEnabledFlag; |
---|
121 | UInt m_numRefLayerLocationOffsets; |
---|
122 | UInt m_refLocationOffsetLayerId[MAX_LAYERS]; |
---|
123 | Window m_scaledRefLayerWindow[MAX_LAYERS]; |
---|
124 | UInt m_numRefLayerOffsets; |
---|
125 | UInt m_refLayerId[MAX_LAYERS]; |
---|
126 | Window m_refLayerWindow[MAX_LAYERS]; |
---|
127 | Bool m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS]; |
---|
128 | Bool m_refRegionOffsetPresentFlag[MAX_LAYERS]; |
---|
129 | Int m_phaseHorLuma [MAX_LAYERS]; |
---|
130 | Int m_phaseVerLuma [MAX_LAYERS]; |
---|
131 | Int m_phaseHorChroma[MAX_LAYERS]; |
---|
132 | Int m_phaseVerChroma[MAX_LAYERS]; |
---|
133 | Int m_resamplePhaseSetPresentFlag[MAX_LAYERS]; |
---|
134 | Int m_pocAdjustmentValue; |
---|
135 | #if NO_CLRAS_OUTPUT_FLAG |
---|
136 | Bool m_noClrasOutputFlag; |
---|
137 | Bool m_layerInitializedFlag; |
---|
138 | Bool m_firstPicInLayerDecodedFlag; |
---|
139 | Bool m_noOutputOfPriorPicsFlags; |
---|
140 | #endif |
---|
141 | Bool m_interLayerWeightedPredFlag; |
---|
142 | Int m_numAddLayerSets; |
---|
143 | Bool m_pocDecrementedInDPBFlag; |
---|
144 | Int m_currPocMsb; |
---|
145 | Bool m_prevPicHasEos; |
---|
146 | #endif //SVC_EXTENSION |
---|
147 | protected: |
---|
148 | Void xGetNewPicBuffer ( TComPic*& rpcPic ); ///< get picture buffer which will be processed |
---|
149 | Void xInitVPS (); ///< initialize VPS from encoder options |
---|
150 | Void xInitSPS (); ///< initialize SPS from encoder options |
---|
151 | Void xInitPPS (); ///< initialize PPS from encoder options |
---|
152 | Void xInitScalingLists (); ///< initialize scaling lists |
---|
153 | Void xInitHrdParameters(); ///< initialize HRD parameters |
---|
154 | |
---|
155 | Void xInitPPSforTiles (); |
---|
156 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
157 | #if SVC_EXTENSION |
---|
158 | Void xInitILRP(); |
---|
159 | #endif |
---|
160 | public: |
---|
161 | TEncTop(); |
---|
162 | virtual ~TEncTop(); |
---|
163 | |
---|
164 | Void create (); |
---|
165 | Void destroy (); |
---|
166 | Void init (Bool isFieldCoding); |
---|
167 | Void deletePicBuffer (); |
---|
168 | |
---|
169 | // ------------------------------------------------------------------------------------------------------------------- |
---|
170 | // member access functions |
---|
171 | // ------------------------------------------------------------------------------------------------------------------- |
---|
172 | |
---|
173 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
174 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
175 | |
---|
176 | TComTrQuant* getTrQuant () { return &m_cTrQuant; } |
---|
177 | TComLoopFilter* getLoopFilter () { return &m_cLoopFilter; } |
---|
178 | TEncSampleAdaptiveOffset* getSAO () { return &m_cEncSAO; } |
---|
179 | TEncGOP* getGOPEncoder () { return &m_cGOPEncoder; } |
---|
180 | TEncSlice* getSliceEncoder () { return &m_cSliceEncoder; } |
---|
181 | TEncCu* getCuEncoder () { return &m_cCuEncoder; } |
---|
182 | TEncEntropy* getEntropyCoder () { return &m_cEntropyCoder; } |
---|
183 | TEncCavlc* getCavlcCoder () { return &m_cCavlcCoder; } |
---|
184 | TEncSbac* getSbacCoder () { return &m_cSbacCoder; } |
---|
185 | TEncBinCABAC* getBinCABAC () { return &m_cBinCoderCABAC; } |
---|
186 | |
---|
187 | TComRdCost* getRdCost () { return &m_cRdCost; } |
---|
188 | TEncSbac*** getRDSbacCoder () { return m_pppcRDSbacCoder; } |
---|
189 | TEncSbac* getRDGoOnSbacCoder () { return &m_cRDGoOnSbacCoder; } |
---|
190 | TEncRateCtrl* getRateCtrl () { return &m_cRateCtrl; } |
---|
191 | Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
192 | Int getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid ); |
---|
193 | // ------------------------------------------------------------------------------------------------------------------- |
---|
194 | // encoder function |
---|
195 | // ------------------------------------------------------------------------------------------------------------------- |
---|
196 | |
---|
197 | /// encode several number of pictures until end-of-sequence |
---|
198 | #if SVC_EXTENSION |
---|
199 | TComSPS* getSPS() { return &m_cSPS; } |
---|
200 | #if CGS_3D_ASYMLUT |
---|
201 | TComPPS* getPPS() { return &m_cPPS; } |
---|
202 | #endif |
---|
203 | Void setLayerEnc(TEncTop** p) { m_ppcTEncTop = p; } |
---|
204 | TEncTop** getLayerEnc() { return m_ppcTEncTop; } |
---|
205 | Int getPOCLast() { return m_iPOCLast; } |
---|
206 | Int getNumPicRcvd() { return m_iNumPicRcvd; } |
---|
207 | Void setNumPicRcvd( Int num ) { m_iNumPicRcvd = num; } |
---|
208 | Void setNumRefLayerLocationOffsets(Int x) { m_numRefLayerLocationOffsets = x; } |
---|
209 | UInt getNumRefLayerLocationOffsets() { return m_numRefLayerLocationOffsets; } |
---|
210 | Void setRefLocationOffsetLayerId(Int x, UInt id) { m_refLocationOffsetLayerId[x] = id; } |
---|
211 | UInt getRefLocationOffsetLayerId(Int x) { return m_refLocationOffsetLayerId[x]; } |
---|
212 | Window getScaledRefLayerWindowForLayer(Int layerId); |
---|
213 | Window& getScaledRefLayerWindow(Int x) { return m_scaledRefLayerWindow[x]; } |
---|
214 | Void setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; } |
---|
215 | UInt getNumRefLayerOffsets() { return m_numRefLayerOffsets; } |
---|
216 | Void setRefLayerId(Int layerIdx, UInt layerId) { m_refLayerId[layerIdx] = layerId; } |
---|
217 | UInt getRefLayerId(Int layerIdx) { return m_refLayerId[layerIdx]; } |
---|
218 | Window getRefLayerWindowForLayer(Int layerId); |
---|
219 | Window& getRefLayerWindow(Int x) { return m_refLayerWindow[x]; } |
---|
220 | Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; } |
---|
221 | Void setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; } |
---|
222 | Bool getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; } |
---|
223 | Void setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; } |
---|
224 | Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; } |
---|
225 | Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; } |
---|
226 | Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; } |
---|
227 | Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; } |
---|
228 | Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; } |
---|
229 | Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; } |
---|
230 | Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; } |
---|
231 | Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; } |
---|
232 | Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; } |
---|
233 | Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; } |
---|
234 | |
---|
235 | TComPic** getIlpList() { return m_cIlpPic; } |
---|
236 | Void setMFMEnabledFlag(Bool flag) { m_bMFMEnabledFlag = flag; } |
---|
237 | Bool getMFMEnabledFlag() { return m_bMFMEnabledFlag; } |
---|
238 | Void setInterLayerWeightedPredFlag(Bool flag) { m_interLayerWeightedPredFlag = flag; } |
---|
239 | Bool getInterLayerWeightedPredFlag() { return m_interLayerWeightedPredFlag; } |
---|
240 | |
---|
241 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ); |
---|
242 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ); |
---|
243 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ); |
---|
244 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ); |
---|
245 | |
---|
246 | TEncTop* getRefLayerEnc(UInt refLayerIdx); |
---|
247 | |
---|
248 | Int getPocAdjustmentValue() { return m_pocAdjustmentValue;} |
---|
249 | Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x; } |
---|
250 | #if NO_CLRAS_OUTPUT_FLAG |
---|
251 | Int getNoClrasOutputFlag() { return m_noClrasOutputFlag;} |
---|
252 | Void setNoClrasOutputFlag(Bool x) { m_noClrasOutputFlag = x; } |
---|
253 | Int getLayerInitializedFlag() { return m_layerInitializedFlag;} |
---|
254 | Void setLayerInitializedFlag(Bool x) { m_layerInitializedFlag = x; } |
---|
255 | Int getFirstPicInLayerDecodedFlag() { return m_firstPicInLayerDecodedFlag;} |
---|
256 | Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x; } |
---|
257 | Int getNoOutputOfPriorPicsFlags() { return m_noOutputOfPriorPicsFlags;} |
---|
258 | Void setNoOutputOfPriorPicsFlags(Bool x) { m_noOutputOfPriorPicsFlags = x; } |
---|
259 | #endif |
---|
260 | Void setNumAddLayerSets(Int x) { m_numAddLayerSets = x; } |
---|
261 | Int getNumAddLayerSets() { return m_numAddLayerSets; } |
---|
262 | Void setPocDecrementedInDPBFlag(Bool x) { m_pocDecrementedInDPBFlag = x; } |
---|
263 | Bool getPocDecrementedInDPBFlag() { return m_pocDecrementedInDPBFlag; } |
---|
264 | Void setCurrPocMsb(Int poc) { m_currPocMsb = poc; } |
---|
265 | Int getCurrPocMsb() { return m_currPocMsb; } |
---|
266 | |
---|
267 | TEncAnalyze* getAnalyzeAll() { return m_cGOPEncoder.getAnalyzeAll(); } |
---|
268 | TEncAnalyze* getAnalyzeI() { return m_cGOPEncoder.getAnalyzeI(); } |
---|
269 | TEncAnalyze* getAnalyzeP() { return m_cGOPEncoder.getAnalyzeP(); } |
---|
270 | TEncAnalyze* getAnalyzeB() { return m_cGOPEncoder.getAnalyzeB(); } |
---|
271 | TEncAnalyze* getAnalyzeAllin() { return m_cGOPEncoder.getAnalyzeAllin(); } |
---|
272 | Double calculateRVM() { return m_cGOPEncoder.calculateRVM(); } |
---|
273 | #else //SVC_EXTENSION |
---|
274 | Void encode( Bool bEos, |
---|
275 | TComPicYuv* pcPicYuvOrg, |
---|
276 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
277 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
278 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
279 | |
---|
280 | /// encode several number of pictures until end-of-sequence |
---|
281 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, |
---|
282 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
283 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
284 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff); |
---|
285 | #endif //#if SVC_EXTENSION |
---|
286 | |
---|
287 | Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField, m_printMSEBasedSequencePSNR, m_printSequenceMSE, m_cSPS.getBitDepths()); } |
---|
288 | |
---|
289 | }; |
---|
290 | |
---|
291 | //! \} |
---|
292 | |
---|
293 | #endif // __TENCTOP__ |
---|
294 | |
---|