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-2014, 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 |
---|
96 | TComPPS m_cPPS; ///< PPS |
---|
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 | TComScalingList m_scalingList; ///< quantization matrix information |
---|
113 | TEncRateCtrl m_cRateCtrl; ///< Rate control class |
---|
114 | |
---|
115 | #if SVC_EXTENSION |
---|
116 | static Int m_iSPSIdCnt; ///< next Id number for SPS |
---|
117 | static Int m_iPPSIdCnt; ///< next Id number for PPS |
---|
118 | TEncTop** m_ppcTEncTop; |
---|
119 | TEncTop* getLayerEnc(UInt layer) { return m_ppcTEncTop[layer]; } |
---|
120 | TComPic* m_cIlpPic[MAX_NUM_REF]; ///< Inter layer Prediction picture = upsampled picture |
---|
121 | #if REF_IDX_MFM |
---|
122 | Bool m_bMFMEnabledFlag; |
---|
123 | #endif |
---|
124 | UInt m_numScaledRefLayerOffsets; |
---|
125 | #if O0098_SCALED_REF_LAYER_ID |
---|
126 | UInt m_scaledRefLayerId[MAX_LAYERS]; |
---|
127 | #endif |
---|
128 | Window m_scaledRefLayerWindow[MAX_LAYERS]; |
---|
129 | #if REF_REGION_OFFSET |
---|
130 | UInt m_numRefLayerOffsets; |
---|
131 | UInt m_refLayerId[MAX_LAYERS]; |
---|
132 | Window m_refLayerWindow[MAX_LAYERS]; |
---|
133 | Bool m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS]; |
---|
134 | Bool m_refRegionOffsetPresentFlag[MAX_LAYERS]; |
---|
135 | #endif |
---|
136 | #if R0209_GENERIC_PHASE |
---|
137 | Int m_phaseHorLuma [MAX_LAYERS]; |
---|
138 | Int m_phaseVerLuma [MAX_LAYERS]; |
---|
139 | Int m_phaseHorChroma[MAX_LAYERS]; |
---|
140 | Int m_phaseVerChroma[MAX_LAYERS]; |
---|
141 | Int m_resamplePhaseSetPresentFlag[MAX_LAYERS]; |
---|
142 | #endif |
---|
143 | #if P0312_VERT_PHASE_ADJ |
---|
144 | Bool m_vertPhasePositionEnableFlag[MAX_LAYERS]; |
---|
145 | #endif |
---|
146 | #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER |
---|
147 | Int m_pocAdjustmentValue; |
---|
148 | #endif |
---|
149 | #if NO_CLRAS_OUTPUT_FLAG |
---|
150 | Bool m_noClrasOutputFlag; |
---|
151 | Bool m_layerInitializedFlag; |
---|
152 | Bool m_firstPicInLayerDecodedFlag; |
---|
153 | Bool m_noOutputOfPriorPicsFlags; |
---|
154 | #endif |
---|
155 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
156 | Bool m_interLayerWeightedPredFlag; |
---|
157 | #endif |
---|
158 | #if Q0078_ADD_LAYER_SETS |
---|
159 | int m_numAddLayerSets; |
---|
160 | #endif |
---|
161 | #if P0297_VPS_POC_LSB_ALIGNED_FLAG |
---|
162 | Bool m_pocDecrementedInDPBFlag; |
---|
163 | Int m_currPocMsb; |
---|
164 | #endif |
---|
165 | #if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS |
---|
166 | Bool m_prevPicHasEos; |
---|
167 | #endif |
---|
168 | #endif //SVC_EXTENSION |
---|
169 | protected: |
---|
170 | Void xGetNewPicBuffer ( TComPic*& rpcPic ); ///< get picture buffer which will be processed |
---|
171 | Void xInitSPS (); ///< initialize SPS from encoder options |
---|
172 | Void xInitPPS (); ///< initialize PPS from encoder options |
---|
173 | |
---|
174 | Void xInitPPSforTiles (); |
---|
175 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
176 | #if SVC_EXTENSION |
---|
177 | Void xInitILRP(); |
---|
178 | #endif |
---|
179 | public: |
---|
180 | TEncTop(); |
---|
181 | virtual ~TEncTop(); |
---|
182 | |
---|
183 | Void create (); |
---|
184 | Void destroy (); |
---|
185 | Void init (Bool isFieldCoding); |
---|
186 | Void deletePicBuffer (); |
---|
187 | |
---|
188 | // ------------------------------------------------------------------------------------------------------------------- |
---|
189 | // member access functions |
---|
190 | // ------------------------------------------------------------------------------------------------------------------- |
---|
191 | |
---|
192 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
193 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
194 | |
---|
195 | TComTrQuant* getTrQuant () { return &m_cTrQuant; } |
---|
196 | TComLoopFilter* getLoopFilter () { return &m_cLoopFilter; } |
---|
197 | TEncSampleAdaptiveOffset* getSAO () { return &m_cEncSAO; } |
---|
198 | TEncGOP* getGOPEncoder () { return &m_cGOPEncoder; } |
---|
199 | TEncSlice* getSliceEncoder () { return &m_cSliceEncoder; } |
---|
200 | TEncCu* getCuEncoder () { return &m_cCuEncoder; } |
---|
201 | TEncEntropy* getEntropyCoder () { return &m_cEntropyCoder; } |
---|
202 | TEncCavlc* getCavlcCoder () { return &m_cCavlcCoder; } |
---|
203 | TEncSbac* getSbacCoder () { return &m_cSbacCoder; } |
---|
204 | TEncBinCABAC* getBinCABAC () { return &m_cBinCoderCABAC; } |
---|
205 | |
---|
206 | TComRdCost* getRdCost () { return &m_cRdCost; } |
---|
207 | TEncSbac*** getRDSbacCoder () { return m_pppcRDSbacCoder; } |
---|
208 | TEncSbac* getRDGoOnSbacCoder () { return &m_cRDGoOnSbacCoder; } |
---|
209 | TEncRateCtrl* getRateCtrl () { return &m_cRateCtrl; } |
---|
210 | TComSPS* getSPS () { return &m_cSPS; } |
---|
211 | TComPPS* getPPS () { return &m_cPPS; } |
---|
212 | Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
213 | Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
214 | TComScalingList* getScalingList () { return &m_scalingList; } |
---|
215 | // ------------------------------------------------------------------------------------------------------------------- |
---|
216 | // encoder function |
---|
217 | // ------------------------------------------------------------------------------------------------------------------- |
---|
218 | |
---|
219 | /// encode several number of pictures until end-of-sequence |
---|
220 | #if SVC_EXTENSION |
---|
221 | Void setLayerEnc(TEncTop** p) { m_ppcTEncTop = p; } |
---|
222 | TEncTop** getLayerEnc() { return m_ppcTEncTop; } |
---|
223 | Int getPOCLast () { return m_iPOCLast; } |
---|
224 | Int getNumPicRcvd () { return m_iNumPicRcvd; } |
---|
225 | Void setNumPicRcvd ( Int num ) { m_iNumPicRcvd = num; } |
---|
226 | Void setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; } |
---|
227 | UInt getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; } |
---|
228 | #if O0098_SCALED_REF_LAYER_ID |
---|
229 | Void setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id; } |
---|
230 | UInt getScaledRefLayerId(Int x) { return m_scaledRefLayerId[x]; } |
---|
231 | Window& getScaledRefLayerWindowForLayer(Int layerId); |
---|
232 | #endif |
---|
233 | Window& getScaledRefLayerWindow(Int x) { return m_scaledRefLayerWindow[x]; } |
---|
234 | #if REF_REGION_OFFSET |
---|
235 | Void setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; } |
---|
236 | UInt getNumRefLayerOffsets() { return m_numRefLayerOffsets; } |
---|
237 | Void setRefLayerId(Int x, UInt id) { m_refLayerId[x] = id; } |
---|
238 | UInt getRefLayerId(Int x) { return m_refLayerId[x]; } |
---|
239 | Window& getRefLayerWindowForLayer(Int layerId); |
---|
240 | Window& getRefLayerWindow(Int x) { return m_refLayerWindow[x]; } |
---|
241 | Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; } |
---|
242 | Void setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; } |
---|
243 | Bool getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; } |
---|
244 | Void setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; } |
---|
245 | #endif |
---|
246 | #if P0312_VERT_PHASE_ADJ |
---|
247 | Void setVertPhasePositionEnableFlag(Int x, Bool b) { m_vertPhasePositionEnableFlag[x] = b; } |
---|
248 | UInt getVertPhasePositionEnableFlag(Int x) { return m_vertPhasePositionEnableFlag[x]; } |
---|
249 | #endif |
---|
250 | #if R0209_GENERIC_PHASE |
---|
251 | Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; } |
---|
252 | Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; } |
---|
253 | Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; } |
---|
254 | Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; } |
---|
255 | Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; } |
---|
256 | Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; } |
---|
257 | Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; } |
---|
258 | Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; } |
---|
259 | Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; } |
---|
260 | Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; } |
---|
261 | #endif |
---|
262 | |
---|
263 | TComPic** getIlpList() { return m_cIlpPic; } |
---|
264 | #if REF_IDX_MFM |
---|
265 | Void setMFMEnabledFlag (Bool flag) { m_bMFMEnabledFlag = flag; } |
---|
266 | Bool getMFMEnabledFlag() { return m_bMFMEnabledFlag; } |
---|
267 | #endif |
---|
268 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
269 | Void setInterLayerWeightedPredFlag(Bool flag) { m_interLayerWeightedPredFlag = flag; } |
---|
270 | Bool getInterLayerWeightedPredFlag() { return m_interLayerWeightedPredFlag; } |
---|
271 | #endif |
---|
272 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ); |
---|
273 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ); |
---|
274 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ); |
---|
275 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ); |
---|
276 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
277 | TEncTop* getRefLayerEnc(UInt refLayerIdc); |
---|
278 | #endif |
---|
279 | #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER |
---|
280 | Int getPocAdjustmentValue() { return m_pocAdjustmentValue;} |
---|
281 | Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x; } |
---|
282 | #endif |
---|
283 | #if NO_CLRAS_OUTPUT_FLAG |
---|
284 | Int getNoClrasOutputFlag() { return m_noClrasOutputFlag;} |
---|
285 | Void setNoClrasOutputFlag(Bool x) { m_noClrasOutputFlag = x; } |
---|
286 | Int getLayerInitializedFlag() { return m_layerInitializedFlag;} |
---|
287 | Void setLayerInitializedFlag(Bool x) { m_layerInitializedFlag = x; } |
---|
288 | Int getFirstPicInLayerDecodedFlag() { return m_firstPicInLayerDecodedFlag;} |
---|
289 | Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x; } |
---|
290 | Int getNoOutputOfPriorPicsFlags() { return m_noOutputOfPriorPicsFlags;} |
---|
291 | Void setNoOutputOfPriorPicsFlags(Bool x) { m_noOutputOfPriorPicsFlags = x; } |
---|
292 | #endif |
---|
293 | #if Q0078_ADD_LAYER_SETS |
---|
294 | Void setNumAddLayerSets(Int x) { m_numAddLayerSets = x; } |
---|
295 | Int getNumAddLayerSets() { return m_numAddLayerSets; } |
---|
296 | #endif |
---|
297 | #if P0297_VPS_POC_LSB_ALIGNED_FLAG |
---|
298 | Void setPocDecrementedInDPBFlag(Bool x) { m_pocDecrementedInDPBFlag = x; } |
---|
299 | Bool getPocDecrementedInDPBFlag() { return m_pocDecrementedInDPBFlag; } |
---|
300 | Void setCurrPocMsb(Int poc) { m_currPocMsb = poc; } |
---|
301 | Int getCurrPocMsb() { return m_currPocMsb; } |
---|
302 | #endif |
---|
303 | #else //SVC_EXTENSION |
---|
304 | Void encode( Bool bEos, |
---|
305 | TComPicYuv* pcPicYuvOrg, |
---|
306 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
307 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
308 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
309 | |
---|
310 | /// encode several number of pictures until end-of-sequence |
---|
311 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, |
---|
312 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
313 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
314 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff); |
---|
315 | |
---|
316 | Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField, m_printMSEBasedSequencePSNR, m_printSequenceMSE); } |
---|
317 | #endif //#if SVC_EXTENSION |
---|
318 | }; |
---|
319 | |
---|
320 | //! \} |
---|
321 | |
---|
322 | #endif // __TENCTOP__ |
---|
323 | |
---|