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/AccessUnit.h" |
---|
46 | |
---|
47 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
48 | |
---|
49 | #include "TEncCfg.h" |
---|
50 | #include "TEncGOP.h" |
---|
51 | #include "TEncSlice.h" |
---|
52 | #include "TEncEntropy.h" |
---|
53 | #include "TEncCavlc.h" |
---|
54 | #include "TEncSbac.h" |
---|
55 | #include "TEncSearch.h" |
---|
56 | #include "TEncSampleAdaptiveOffset.h" |
---|
57 | #include "TEncPreanalyzer.h" |
---|
58 | #include "TEncRateCtrl.h" |
---|
59 | //! \ingroup TLibEncoder |
---|
60 | //! \{ |
---|
61 | |
---|
62 | // ==================================================================================================================== |
---|
63 | // Class definition |
---|
64 | // ==================================================================================================================== |
---|
65 | |
---|
66 | /// encoder class |
---|
67 | class TEncTop : public TEncCfg |
---|
68 | { |
---|
69 | private: |
---|
70 | // picture |
---|
71 | Int m_iPOCLast; ///< time index (POC) |
---|
72 | Int m_iNumPicRcvd; ///< number of received pictures |
---|
73 | UInt m_uiNumAllPicCoded; ///< number of coded pictures |
---|
74 | TComList<TComPic*> m_cListPic; ///< dynamic list of pictures |
---|
75 | |
---|
76 | // encoder search |
---|
77 | TEncSearch m_cSearch; ///< encoder search class |
---|
78 | //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder |
---|
79 | TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder |
---|
80 | // coding tool |
---|
81 | TComTrQuant m_cTrQuant; ///< transform & quantization class |
---|
82 | TComLoopFilter m_cLoopFilter; ///< deblocking filter class |
---|
83 | TEncSampleAdaptiveOffset m_cEncSAO; ///< sample adaptive offset class |
---|
84 | TEncEntropy m_cEntropyCoder; ///< entropy encoder |
---|
85 | TEncCavlc m_cCavlcCoder; ///< CAVLC encoder |
---|
86 | TEncSbac m_cSbacCoder; ///< SBAC encoder |
---|
87 | TEncBinCABAC m_cBinCoderCABAC; ///< bin coder CABAC |
---|
88 | TEncSbac* m_pcSbacCoders; ///< SBAC encoders (to encode substreams ) |
---|
89 | TEncBinCABAC* m_pcBinCoderCABACs; ///< bin coders CABAC (one per substream) |
---|
90 | |
---|
91 | // processing unit |
---|
92 | TEncGOP m_cGOPEncoder; ///< GOP encoder |
---|
93 | TEncSlice m_cSliceEncoder; ///< slice encoder |
---|
94 | TEncCu m_cCuEncoder; ///< CU encoder |
---|
95 | // SPS |
---|
96 | TComSPS m_cSPS; ///< SPS |
---|
97 | TComPPS m_cPPS; ///< PPS |
---|
98 | // RD cost computation |
---|
99 | TComBitCounter m_cBitCounter; ///< bit counter for RD optimization |
---|
100 | TComRdCost m_cRdCost; ///< RD cost computation class |
---|
101 | TEncSbac*** m_pppcRDSbacCoder; ///< temporal storage for RD computation |
---|
102 | TEncSbac m_cRDGoOnSbacCoder; ///< going on SBAC model for RD stage |
---|
103 | #if FAST_BIT_EST |
---|
104 | TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
105 | TEncBinCABACCounter m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
106 | #else |
---|
107 | TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
108 | TEncBinCABAC m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
109 | #endif |
---|
110 | Int m_iNumSubstreams; ///< # of top-level elements allocated. |
---|
111 | TComBitCounter* m_pcBitCounters; ///< bit counters for RD optimization per substream |
---|
112 | TComRdCost* m_pcRdCosts; ///< RD cost computation class per substream |
---|
113 | TEncSbac**** m_ppppcRDSbacCoders; ///< temporal storage for RD computation per substream |
---|
114 | TEncSbac* m_pcRDGoOnSbacCoders; ///< going on SBAC model for RD stage per substream |
---|
115 | TEncBinCABAC**** m_ppppcBinCodersCABAC; ///< temporal CABAC state storage for RD computation per substream |
---|
116 | TEncBinCABAC* m_pcRDGoOnBinCodersCABAC; ///< going on bin coder CABAC for RD stage per substream |
---|
117 | |
---|
118 | // quality control |
---|
119 | TEncPreanalyzer m_cPreanalyzer; ///< image characteristics analyzer for TM5-step3-like adaptive QP |
---|
120 | |
---|
121 | TComScalingList m_scalingList; ///< quantization matrix information |
---|
122 | TEncRateCtrl m_cRateCtrl; ///< Rate control class |
---|
123 | |
---|
124 | #if SVC_EXTENSION |
---|
125 | static Int m_iSPSIdCnt; ///< next Id number for SPS |
---|
126 | static Int m_iPPSIdCnt; ///< next Id number for PPS |
---|
127 | TEncTop** m_ppcTEncTop; |
---|
128 | TEncTop* getLayerEnc(UInt layer) { return m_ppcTEncTop[layer]; } |
---|
129 | TComPic* m_cIlpPic[MAX_NUM_REF]; ///< Inter layer Prediction picture = upsampled picture |
---|
130 | #if REF_IDX_MFM |
---|
131 | Bool m_bMFMEnabledFlag; |
---|
132 | #endif |
---|
133 | UInt m_numScaledRefLayerOffsets; |
---|
134 | #if O0098_SCALED_REF_LAYER_ID |
---|
135 | UInt m_scaledRefLayerId[MAX_LAYERS]; |
---|
136 | #endif |
---|
137 | Window m_scaledRefLayerWindow[MAX_LAYERS]; |
---|
138 | #if REF_REGION_OFFSET |
---|
139 | UInt m_numRefLayerOffsets; |
---|
140 | UInt m_refLayerId[MAX_LAYERS]; |
---|
141 | Window m_refLayerWindow[MAX_LAYERS]; |
---|
142 | Bool m_scaledRefLayerOffsetPresentFlag[MAX_LAYERS]; |
---|
143 | Bool m_refRegionOffsetPresentFlag[MAX_LAYERS]; |
---|
144 | #endif |
---|
145 | #if R0209_GENERIC_PHASE |
---|
146 | Int m_phaseHorLuma [MAX_LAYERS]; |
---|
147 | Int m_phaseVerLuma [MAX_LAYERS]; |
---|
148 | Int m_phaseHorChroma[MAX_LAYERS]; |
---|
149 | Int m_phaseVerChroma[MAX_LAYERS]; |
---|
150 | Int m_resamplePhaseSetPresentFlag[MAX_LAYERS]; |
---|
151 | #endif |
---|
152 | #if P0312_VERT_PHASE_ADJ |
---|
153 | Bool m_vertPhasePositionEnableFlag[MAX_LAYERS]; |
---|
154 | #endif |
---|
155 | #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER |
---|
156 | Int m_pocAdjustmentValue; |
---|
157 | #endif |
---|
158 | #if NO_CLRAS_OUTPUT_FLAG |
---|
159 | Bool m_noClrasOutputFlag; |
---|
160 | Bool m_layerInitializedFlag; |
---|
161 | Bool m_firstPicInLayerDecodedFlag; |
---|
162 | Bool m_noOutputOfPriorPicsFlags; |
---|
163 | #endif |
---|
164 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
165 | Bool m_interLayerWeightedPredFlag; |
---|
166 | #endif |
---|
167 | #if Q0078_ADD_LAYER_SETS |
---|
168 | int m_numAddLayerSets; |
---|
169 | #endif |
---|
170 | #if P0297_VPS_POC_LSB_ALIGNED_FLAG |
---|
171 | Bool m_pocDecrementedInDPBFlag; |
---|
172 | Int m_currPocMsb; |
---|
173 | #endif |
---|
174 | #endif //SVC_EXTENSION |
---|
175 | protected: |
---|
176 | Void xGetNewPicBuffer ( TComPic*& rpcPic ); ///< get picture buffer which will be processed |
---|
177 | Void xInitSPS (); ///< initialize SPS from encoder options |
---|
178 | Void xInitPPS (); ///< initialize PPS from encoder options |
---|
179 | |
---|
180 | Void xInitPPSforTiles (); |
---|
181 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
182 | #if SVC_EXTENSION |
---|
183 | Void xInitILRP(); |
---|
184 | #endif |
---|
185 | public: |
---|
186 | TEncTop(); |
---|
187 | virtual ~TEncTop(); |
---|
188 | |
---|
189 | Void create (); |
---|
190 | Void destroy (); |
---|
191 | Void init (Bool isFieldCoding); |
---|
192 | Void deletePicBuffer (); |
---|
193 | |
---|
194 | Void createWPPCoders(Int iNumSubstreams); |
---|
195 | |
---|
196 | // ------------------------------------------------------------------------------------------------------------------- |
---|
197 | // member access functions |
---|
198 | // ------------------------------------------------------------------------------------------------------------------- |
---|
199 | |
---|
200 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
201 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
202 | |
---|
203 | TComTrQuant* getTrQuant () { return &m_cTrQuant; } |
---|
204 | TComLoopFilter* getLoopFilter () { return &m_cLoopFilter; } |
---|
205 | TEncSampleAdaptiveOffset* getSAO () { return &m_cEncSAO; } |
---|
206 | TEncGOP* getGOPEncoder () { return &m_cGOPEncoder; } |
---|
207 | TEncSlice* getSliceEncoder () { return &m_cSliceEncoder; } |
---|
208 | TEncCu* getCuEncoder () { return &m_cCuEncoder; } |
---|
209 | TEncEntropy* getEntropyCoder () { return &m_cEntropyCoder; } |
---|
210 | TEncCavlc* getCavlcCoder () { return &m_cCavlcCoder; } |
---|
211 | TEncSbac* getSbacCoder () { return &m_cSbacCoder; } |
---|
212 | TEncBinCABAC* getBinCABAC () { return &m_cBinCoderCABAC; } |
---|
213 | TEncSbac* getSbacCoders () { return m_pcSbacCoders; } |
---|
214 | TEncBinCABAC* getBinCABACs () { return m_pcBinCoderCABACs; } |
---|
215 | |
---|
216 | TComBitCounter* getBitCounter () { return &m_cBitCounter; } |
---|
217 | TComRdCost* getRdCost () { return &m_cRdCost; } |
---|
218 | TEncSbac*** getRDSbacCoder () { return m_pppcRDSbacCoder; } |
---|
219 | TEncSbac* getRDGoOnSbacCoder () { return &m_cRDGoOnSbacCoder; } |
---|
220 | TComBitCounter* getBitCounters () { return m_pcBitCounters; } |
---|
221 | TComRdCost* getRdCosts () { return m_pcRdCosts; } |
---|
222 | TEncSbac**** getRDSbacCoders () { return m_ppppcRDSbacCoders; } |
---|
223 | TEncSbac* getRDGoOnSbacCoders () { return m_pcRDGoOnSbacCoders; } |
---|
224 | TEncRateCtrl* getRateCtrl () { return &m_cRateCtrl; } |
---|
225 | TComSPS* getSPS () { return &m_cSPS; } |
---|
226 | TComPPS* getPPS () { return &m_cPPS; } |
---|
227 | Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
228 | Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
229 | TComScalingList* getScalingList () { return &m_scalingList; } |
---|
230 | // ------------------------------------------------------------------------------------------------------------------- |
---|
231 | // encoder function |
---|
232 | // ------------------------------------------------------------------------------------------------------------------- |
---|
233 | |
---|
234 | /// encode several number of pictures until end-of-sequence |
---|
235 | #if SVC_EXTENSION |
---|
236 | Void setLayerEnc(TEncTop** p) { m_ppcTEncTop = p; } |
---|
237 | TEncTop** getLayerEnc() { return m_ppcTEncTop; } |
---|
238 | Int getPOCLast () { return m_iPOCLast; } |
---|
239 | Int getNumPicRcvd () { return m_iNumPicRcvd; } |
---|
240 | Void setNumPicRcvd ( Int num ) { m_iNumPicRcvd = num; } |
---|
241 | Void setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; } |
---|
242 | UInt getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; } |
---|
243 | #if O0098_SCALED_REF_LAYER_ID |
---|
244 | Void setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id; } |
---|
245 | UInt getScaledRefLayerId(Int x) { return m_scaledRefLayerId[x]; } |
---|
246 | Window& getScaledRefLayerWindowForLayer(Int layerId); |
---|
247 | #endif |
---|
248 | Window& getScaledRefLayerWindow(Int x) { return m_scaledRefLayerWindow[x]; } |
---|
249 | #if REF_REGION_OFFSET |
---|
250 | Void setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; } |
---|
251 | UInt getNumRefLayerOffsets() { return m_numRefLayerOffsets; } |
---|
252 | Void setRefLayerId(Int x, UInt id) { m_refLayerId[x] = id; } |
---|
253 | UInt getRefLayerId(Int x) { return m_refLayerId[x]; } |
---|
254 | Window& getRefLayerWindowForLayer(Int layerId); |
---|
255 | Window& getRefLayerWindow(Int x) { return m_refLayerWindow[x]; } |
---|
256 | Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; } |
---|
257 | Void setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; } |
---|
258 | Bool getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; } |
---|
259 | Void setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; } |
---|
260 | #endif |
---|
261 | #if P0312_VERT_PHASE_ADJ |
---|
262 | Void setVertPhasePositionEnableFlag(Int x, Bool b) { m_vertPhasePositionEnableFlag[x] = b; } |
---|
263 | UInt getVertPhasePositionEnableFlag(Int x) { return m_vertPhasePositionEnableFlag[x]; } |
---|
264 | #endif |
---|
265 | #if R0209_GENERIC_PHASE |
---|
266 | Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; } |
---|
267 | Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; } |
---|
268 | Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; } |
---|
269 | Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; } |
---|
270 | Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; } |
---|
271 | Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; } |
---|
272 | Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; } |
---|
273 | Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; } |
---|
274 | Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; } |
---|
275 | Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; } |
---|
276 | #endif |
---|
277 | |
---|
278 | TComPic** getIlpList() { return m_cIlpPic; } |
---|
279 | #if REF_IDX_MFM |
---|
280 | Void setMFMEnabledFlag (Bool flag) { m_bMFMEnabledFlag = flag; } |
---|
281 | Bool getMFMEnabledFlag() { return m_bMFMEnabledFlag; } |
---|
282 | #endif |
---|
283 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
284 | Void setInterLayerWeightedPredFlag(Bool flag) { m_interLayerWeightedPredFlag = flag; } |
---|
285 | Bool getInterLayerWeightedPredFlag() { return m_interLayerWeightedPredFlag; } |
---|
286 | #endif |
---|
287 | Void encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ); |
---|
288 | Void encodePrep( TComPicYuv* pcPicYuvOrg ); |
---|
289 | Void encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ); |
---|
290 | Void encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff ); |
---|
291 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
292 | TEncTop* getRefLayerEnc(UInt refLayerIdc); |
---|
293 | #endif |
---|
294 | #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER |
---|
295 | Int getPocAdjustmentValue() { return m_pocAdjustmentValue;} |
---|
296 | Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x; } |
---|
297 | #endif |
---|
298 | #if NO_CLRAS_OUTPUT_FLAG |
---|
299 | Int getNoClrasOutputFlag() { return m_noClrasOutputFlag;} |
---|
300 | Void setNoClrasOutputFlag(Bool x) { m_noClrasOutputFlag = x; } |
---|
301 | Int getLayerInitializedFlag() { return m_layerInitializedFlag;} |
---|
302 | Void setLayerInitializedFlag(Bool x) { m_layerInitializedFlag = x; } |
---|
303 | Int getFirstPicInLayerDecodedFlag() { return m_firstPicInLayerDecodedFlag;} |
---|
304 | Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x; } |
---|
305 | Int getNoOutputOfPriorPicsFlags() { return m_noOutputOfPriorPicsFlags;} |
---|
306 | Void setNoOutputOfPriorPicsFlags(Bool x) { m_noOutputOfPriorPicsFlags = x; } |
---|
307 | #endif |
---|
308 | #if Q0078_ADD_LAYER_SETS |
---|
309 | Void setNumAddLayerSets(Int x) { m_numAddLayerSets = x; } |
---|
310 | Int getNumAddLayerSets() { return m_numAddLayerSets; } |
---|
311 | #endif |
---|
312 | #if P0297_VPS_POC_LSB_ALIGNED_FLAG |
---|
313 | Void setPocDecrementedInDPBFlag(Bool x) { m_pocDecrementedInDPBFlag = x; } |
---|
314 | Bool getPocDecrementedInDPBFlag() { return m_pocDecrementedInDPBFlag; } |
---|
315 | Void setCurrPocMsb(Int poc) { m_currPocMsb = poc; } |
---|
316 | Int getCurrPocMsb() { return m_currPocMsb; } |
---|
317 | #endif |
---|
318 | #else //SVC_EXTENSION |
---|
319 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
320 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
321 | |
---|
322 | /// encode several number of pictures until end-of-sequence |
---|
323 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
324 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff); |
---|
325 | |
---|
326 | Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); } |
---|
327 | #endif //#if SVC_EXTENSION |
---|
328 | }; |
---|
329 | |
---|
330 | //! \} |
---|
331 | |
---|
332 | #endif // __TENCTOP__ |
---|
333 | |
---|