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 | |
---|
154 | Void xInitPPSforTiles (); |
---|
155 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
156 | #if SVC_EXTENSION |
---|
157 | Void xInitILRP(); |
---|
158 | #endif |
---|
159 | public: |
---|
160 | TEncTop(); |
---|
161 | virtual ~TEncTop(); |
---|
162 | |
---|
163 | Void create (); |
---|
164 | Void destroy (); |
---|
165 | Void init (Bool isFieldCoding); |
---|
166 | Void deletePicBuffer (); |
---|
167 | |
---|
168 | // ------------------------------------------------------------------------------------------------------------------- |
---|
169 | // member access functions |
---|
170 | // ------------------------------------------------------------------------------------------------------------------- |
---|
171 | |
---|
172 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
173 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
174 | |
---|
175 | TComTrQuant* getTrQuant () { return &m_cTrQuant; } |
---|
176 | TComLoopFilter* getLoopFilter () { return &m_cLoopFilter; } |
---|
177 | TEncSampleAdaptiveOffset* getSAO () { return &m_cEncSAO; } |
---|
178 | TEncGOP* getGOPEncoder () { return &m_cGOPEncoder; } |
---|
179 | TEncSlice* getSliceEncoder () { return &m_cSliceEncoder; } |
---|
180 | TEncCu* getCuEncoder () { return &m_cCuEncoder; } |
---|
181 | TEncEntropy* getEntropyCoder () { return &m_cEntropyCoder; } |
---|
182 | TEncCavlc* getCavlcCoder () { return &m_cCavlcCoder; } |
---|
183 | TEncSbac* getSbacCoder () { return &m_cSbacCoder; } |
---|
184 | TEncBinCABAC* getBinCABAC () { return &m_cBinCoderCABAC; } |
---|
185 | |
---|
186 | TComRdCost* getRdCost () { return &m_cRdCost; } |
---|
187 | TEncSbac*** getRDSbacCoder () { return m_pppcRDSbacCoder; } |
---|
188 | TEncSbac* getRDGoOnSbacCoder () { return &m_cRDGoOnSbacCoder; } |
---|
189 | TEncRateCtrl* getRateCtrl () { return &m_cRateCtrl; } |
---|
190 | Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
191 | Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
192 | // ------------------------------------------------------------------------------------------------------------------- |
---|
193 | // encoder function |
---|
194 | // ------------------------------------------------------------------------------------------------------------------- |
---|
195 | |
---|
196 | /// encode several number of pictures until end-of-sequence |
---|
197 | #if SVC_EXTENSION |
---|
198 | TComSPS* getSPS() { return &m_cSPS; } |
---|
199 | #if CGS_3D_ASYMLUT |
---|
200 | TComPPS* getPPS() { return &m_cPPS; } |
---|
201 | #endif |
---|
202 | Void setLayerEnc(TEncTop** p) { m_ppcTEncTop = p; } |
---|
203 | TEncTop** getLayerEnc() { return m_ppcTEncTop; } |
---|
204 | Int getPOCLast() { return m_iPOCLast; } |
---|
205 | Int getNumPicRcvd() { return m_iNumPicRcvd; } |
---|
206 | Void setNumPicRcvd( Int num ) { m_iNumPicRcvd = num; } |
---|
207 | Void setNumRefLayerLocationOffsets(Int x) { m_numRefLayerLocationOffsets = x; } |
---|
208 | UInt getNumRefLayerLocationOffsets() { return m_numRefLayerLocationOffsets; } |
---|
209 | Void setRefLocationOffsetLayerId(Int x, UInt id) { m_refLocationOffsetLayerId[x] = id; } |
---|
210 | UInt getRefLocationOffsetLayerId(Int x) { return m_refLocationOffsetLayerId[x]; } |
---|
211 | Window getScaledRefLayerWindowForLayer(Int layerId); |
---|
212 | Window& getScaledRefLayerWindow(Int x) { return m_scaledRefLayerWindow[x]; } |
---|
213 | Void setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; } |
---|
214 | UInt getNumRefLayerOffsets() { return m_numRefLayerOffsets; } |
---|
215 | Void setRefLayerId(Int layerIdx, UInt layerId) { m_refLayerId[layerIdx] = layerId; } |
---|
216 | UInt getRefLayerId(Int layerIdx) { return m_refLayerId[layerIdx]; } |
---|
217 | Window getRefLayerWindowForLayer(Int layerId); |
---|
218 | Window& getRefLayerWindow(Int x) { return m_refLayerWindow[x]; } |
---|
219 | Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; } |
---|
220 | Void setScaledRefLayerOffsetPresentFlag(Int x, Bool b) { m_scaledRefLayerOffsetPresentFlag[x] = b; } |
---|
221 | Bool getRefRegionOffsetPresentFlag(Int x) { return m_refRegionOffsetPresentFlag[x]; } |
---|
222 | Void setRefRegionOffsetPresentFlag(Int x, Bool b) { m_refRegionOffsetPresentFlag[x] = b; } |
---|
223 | Int getPhaseHorLuma(Int x) { return m_phaseHorLuma[x]; } |
---|
224 | Int getPhaseVerLuma(Int x) { return m_phaseVerLuma[x]; } |
---|
225 | Int getPhaseHorChroma(Int x) { return m_phaseHorChroma[x]; } |
---|
226 | Int getPhaseVerChroma(Int x) { return m_phaseVerChroma[x]; } |
---|
227 | Void setPhaseHorLuma(Int x, Int val) { m_phaseHorLuma[x] = val; } |
---|
228 | Void setPhaseVerLuma(Int x, Int val) { m_phaseVerLuma[x] = val; } |
---|
229 | Void setPhaseHorChroma(Int x, Int val) { m_phaseHorChroma[x] = val; } |
---|
230 | Void setPhaseVerChroma(Int x, Int val) { m_phaseVerChroma[x] = val; } |
---|
231 | Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; } |
---|
232 | Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; } |
---|
233 | |
---|
234 | TComPic** getIlpList() { return m_cIlpPic; } |
---|
235 | Void setMFMEnabledFlag(Bool flag) { m_bMFMEnabledFlag = flag; } |
---|
236 | Bool getMFMEnabledFlag() { return m_bMFMEnabledFlag; } |
---|
237 | Void setInterLayerWeightedPredFlag(Bool flag) { m_interLayerWeightedPredFlag = flag; } |
---|
238 | Bool getInterLayerWeightedPredFlag() { return m_interLayerWeightedPredFlag; } |
---|
239 | |
---|
240 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ); |
---|
241 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ); |
---|
242 | Void encode ( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ); |
---|
243 | Void encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ); |
---|
244 | |
---|
245 | TEncTop* getRefLayerEnc(UInt refLayerIdx); |
---|
246 | |
---|
247 | Int getPocAdjustmentValue() { return m_pocAdjustmentValue;} |
---|
248 | Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x; } |
---|
249 | #if NO_CLRAS_OUTPUT_FLAG |
---|
250 | Int getNoClrasOutputFlag() { return m_noClrasOutputFlag;} |
---|
251 | Void setNoClrasOutputFlag(Bool x) { m_noClrasOutputFlag = x; } |
---|
252 | Int getLayerInitializedFlag() { return m_layerInitializedFlag;} |
---|
253 | Void setLayerInitializedFlag(Bool x) { m_layerInitializedFlag = x; } |
---|
254 | Int getFirstPicInLayerDecodedFlag() { return m_firstPicInLayerDecodedFlag;} |
---|
255 | Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x; } |
---|
256 | Int getNoOutputOfPriorPicsFlags() { return m_noOutputOfPriorPicsFlags;} |
---|
257 | Void setNoOutputOfPriorPicsFlags(Bool x) { m_noOutputOfPriorPicsFlags = x; } |
---|
258 | #endif |
---|
259 | Void setNumAddLayerSets(Int x) { m_numAddLayerSets = x; } |
---|
260 | Int getNumAddLayerSets() { return m_numAddLayerSets; } |
---|
261 | Void setPocDecrementedInDPBFlag(Bool x) { m_pocDecrementedInDPBFlag = x; } |
---|
262 | Bool getPocDecrementedInDPBFlag() { return m_pocDecrementedInDPBFlag; } |
---|
263 | Void setCurrPocMsb(Int poc) { m_currPocMsb = poc; } |
---|
264 | Int getCurrPocMsb() { return m_currPocMsb; } |
---|
265 | #else //SVC_EXTENSION |
---|
266 | Void encode( Bool bEos, |
---|
267 | TComPicYuv* pcPicYuvOrg, |
---|
268 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
269 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
270 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
271 | |
---|
272 | /// encode several number of pictures until end-of-sequence |
---|
273 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, |
---|
274 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
275 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
276 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff); |
---|
277 | |
---|
278 | Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField, m_printMSEBasedSequencePSNR, m_printSequenceMSE); } |
---|
279 | #endif //#if SVC_EXTENSION |
---|
280 | }; |
---|
281 | |
---|
282 | //! \} |
---|
283 | |
---|
284 | #endif // __TENCTOP__ |
---|
285 | |
---|