[313] | 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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 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" |
---|
[1029] | 45 | #include "TLibCommon/TComLoopFilter.h" |
---|
[313] | 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 |
---|
[1029] | 76 | |
---|
[313] | 77 | // encoder search |
---|
| 78 | TEncSearch m_cSearch; ///< encoder search class |
---|
[540] | 79 | //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder |
---|
[1029] | 80 | TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder |
---|
[313] | 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 |
---|
[1029] | 89 | |
---|
[313] | 90 | // processing unit |
---|
| 91 | TEncGOP m_cGOPEncoder; ///< GOP encoder |
---|
| 92 | TEncSlice m_cSliceEncoder; ///< slice encoder |
---|
| 93 | TEncCu m_cCuEncoder; ///< CU encoder |
---|
| 94 | // SPS |
---|
[1235] | 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 |
---|
[313] | 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 |
---|
[595] | 115 | static Int m_iSPSIdCnt; ///< next Id number for SPS |
---|
| 116 | static Int m_iPPSIdCnt; ///< next Id number for PPS |
---|
[313] | 117 | TEncTop** m_ppcTEncTop; |
---|
[1287] | 118 | TEncTop* getLayerEnc(UInt layerIdx) { return m_ppcTEncTop[layerIdx]; } |
---|
[313] | 119 | TComPic* m_cIlpPic[MAX_NUM_REF]; ///< Inter layer Prediction picture = upsampled picture |
---|
| 120 | Bool m_bMFMEnabledFlag; |
---|
[1030] | 121 | UInt m_numRefLayerLocationOffsets; |
---|
| 122 | UInt m_refLocationOffsetLayerId[MAX_LAYERS]; |
---|
[313] | 123 | Window m_scaledRefLayerWindow[MAX_LAYERS]; |
---|
[849] | 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]; |
---|
[442] | 134 | Int m_pocAdjustmentValue; |
---|
[540] | 135 | #if NO_CLRAS_OUTPUT_FLAG |
---|
| 136 | Bool m_noClrasOutputFlag; |
---|
| 137 | Bool m_layerInitializedFlag; |
---|
| 138 | Bool m_firstPicInLayerDecodedFlag; |
---|
| 139 | Bool m_noOutputOfPriorPicsFlags; |
---|
| 140 | #endif |
---|
[588] | 141 | Bool m_interLayerWeightedPredFlag; |
---|
[1172] | 142 | Int m_numAddLayerSets; |
---|
[903] | 143 | Bool m_pocDecrementedInDPBFlag; |
---|
| 144 | Int m_currPocMsb; |
---|
[494] | 145 | #endif //SVC_EXTENSION |
---|
[313] | 146 | protected: |
---|
| 147 | Void xGetNewPicBuffer ( TComPic*& rpcPic ); ///< get picture buffer which will be processed |
---|
[1235] | 148 | Void xInitVPS (); ///< initialize VPS from encoder options |
---|
[313] | 149 | Void xInitSPS (); ///< initialize SPS from encoder options |
---|
| 150 | Void xInitPPS (); ///< initialize PPS from encoder options |
---|
[1348] | 151 | Void xInitScalingLists (); ///< initialize scaling lists |
---|
| 152 | Void xInitHrdParameters(); ///< initialize HRD parameters |
---|
[1029] | 153 | |
---|
[313] | 154 | Void xInitPPSforTiles (); |
---|
[442] | 155 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
| 156 | #if SVC_EXTENSION |
---|
[595] | 157 | Void xInitILRP(); |
---|
[313] | 158 | #endif |
---|
| 159 | public: |
---|
| 160 | TEncTop(); |
---|
| 161 | virtual ~TEncTop(); |
---|
[1029] | 162 | |
---|
[313] | 163 | Void create (); |
---|
| 164 | Void destroy (); |
---|
[442] | 165 | Void init (Bool isFieldCoding); |
---|
[313] | 166 | Void deletePicBuffer (); |
---|
| 167 | |
---|
| 168 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 169 | // member access functions |
---|
| 170 | // ------------------------------------------------------------------------------------------------------------------- |
---|
[1029] | 171 | |
---|
[313] | 172 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
| 173 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
[1029] | 174 | |
---|
[313] | 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; } |
---|
[1029] | 185 | |
---|
[313] | 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 ); |
---|
[1307] | 191 | Int getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid ); |
---|
[595] | 192 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 193 | // encoder function |
---|
| 194 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 195 | |
---|
| 196 | /// encode several number of pictures until end-of-sequence |
---|
[313] | 197 | #if SVC_EXTENSION |
---|
[1235] | 198 | TComSPS* getSPS() { return &m_cSPS; } |
---|
| 199 | #if CGS_3D_ASYMLUT |
---|
| 200 | TComPPS* getPPS() { return &m_cPPS; } |
---|
| 201 | #endif |
---|
[1147] | 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; } |
---|
[1235] | 207 | Void setNumRefLayerLocationOffsets(Int x) { m_numRefLayerLocationOffsets = x; } |
---|
| 208 | UInt getNumRefLayerLocationOffsets() { return m_numRefLayerLocationOffsets; } |
---|
[1147] | 209 | Void setRefLocationOffsetLayerId(Int x, UInt id) { m_refLocationOffsetLayerId[x] = id; } |
---|
| 210 | UInt getRefLocationOffsetLayerId(Int x) { return m_refLocationOffsetLayerId[x]; } |
---|
[1235] | 211 | Window getScaledRefLayerWindowForLayer(Int layerId); |
---|
[1147] | 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]; } |
---|
[1235] | 217 | Window getRefLayerWindowForLayer(Int layerId); |
---|
| 218 | Window& getRefLayerWindow(Int x) { return m_refLayerWindow[x]; } |
---|
[1147] | 219 | Bool getScaledRefLayerOffsetPresentFlag(Int x) { return m_scaledRefLayerOffsetPresentFlag[x]; } |
---|
[1235] | 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; } |
---|
[1147] | 231 | Bool getResamplePhaseSetPresentFlag(Int x) { return m_resamplePhaseSetPresentFlag[x]; } |
---|
[1235] | 232 | Void setResamplePhaseSetPresentFlag(Int x, Bool b) { m_resamplePhaseSetPresentFlag[x] = b; } |
---|
[644] | 233 | |
---|
[1235] | 234 | TComPic** getIlpList() { return m_cIlpPic; } |
---|
| 235 | Void setMFMEnabledFlag(Bool flag) { m_bMFMEnabledFlag = flag; } |
---|
| 236 | Bool getMFMEnabledFlag() { return m_bMFMEnabledFlag; } |
---|
[1147] | 237 | Void setInterLayerWeightedPredFlag(Bool flag) { m_interLayerWeightedPredFlag = flag; } |
---|
| 238 | Bool getInterLayerWeightedPredFlag() { return m_interLayerWeightedPredFlag; } |
---|
[1201] | 239 | |
---|
[1029] | 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 ); |
---|
[1148] | 244 | |
---|
[1048] | 245 | TEncTop* getRefLayerEnc(UInt refLayerIdx); |
---|
[1148] | 246 | |
---|
[1209] | 247 | Int getPocAdjustmentValue() { return m_pocAdjustmentValue;} |
---|
| 248 | Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x; } |
---|
[540] | 249 | #if NO_CLRAS_OUTPUT_FLAG |
---|
[1209] | 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; } |
---|
[540] | 258 | #endif |
---|
[1209] | 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; } |
---|
[1292] | 265 | |
---|
| 266 | TEncAnalyze* getAnalyzeAll() { return m_cGOPEncoder.getAnalyzeAll(); } |
---|
| 267 | TEncAnalyze* getAnalyzeI() { return m_cGOPEncoder.getAnalyzeI(); } |
---|
| 268 | TEncAnalyze* getAnalyzeP() { return m_cGOPEncoder.getAnalyzeP(); } |
---|
| 269 | TEncAnalyze* getAnalyzeB() { return m_cGOPEncoder.getAnalyzeB(); } |
---|
| 270 | TEncAnalyze* getAnalyzeAllin() { return m_cGOPEncoder.getAnalyzeAllin(); } |
---|
| 271 | Double calculateRVM() { return m_cGOPEncoder.calculateRVM(); } |
---|
[442] | 272 | #else //SVC_EXTENSION |
---|
[1029] | 273 | Void encode( Bool bEos, |
---|
| 274 | TComPicYuv* pcPicYuvOrg, |
---|
| 275 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
| 276 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 277 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
[313] | 278 | |
---|
[442] | 279 | /// encode several number of pictures until end-of-sequence |
---|
[1029] | 280 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, |
---|
| 281 | TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, // used for SNR calculations. Picture in original colour space. |
---|
| 282 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 283 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff); |
---|
[1292] | 284 | #endif //#if SVC_EXTENSION |
---|
[442] | 285 | |
---|
[1287] | 286 | Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField, m_printMSEBasedSequencePSNR, m_printSequenceMSE, m_cSPS.getBitDepths()); } |
---|
[1307] | 287 | |
---|
[313] | 288 | }; |
---|
| 289 | |
---|
| 290 | //! \} |
---|
| 291 | |
---|
| 292 | #endif // __TENCTOP__ |
---|
[595] | 293 | |
---|