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