[5] | 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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[872] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TEncTop.h |
---|
| 35 | \brief encoder class (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __TENCTOP__ |
---|
| 39 | #define __TENCTOP__ |
---|
| 40 | |
---|
| 41 | // Include files |
---|
[56] | 42 | #include "TLibCommon/TComList.h" |
---|
| 43 | #include "TLibCommon/TComPrediction.h" |
---|
| 44 | #include "TLibCommon/TComTrQuant.h" |
---|
| 45 | #include "TLibCommon/AccessUnit.h" |
---|
[2] | 46 | |
---|
[56] | 47 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
[2] | 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] | 56 | #include "TEncSampleAdaptiveOffset.h" |
---|
| 57 | #include "TEncPreanalyzer.h" |
---|
[608] | 58 | #include "TEncRateCtrl.h" |
---|
[56] | 59 | //! \ingroup TLibEncoder |
---|
| 60 | //! \{ |
---|
[2] | 61 | |
---|
| 62 | // ==================================================================================================================== |
---|
| 63 | // Class definition |
---|
| 64 | // ==================================================================================================================== |
---|
| 65 | |
---|
[655] | 66 | #if KWU_RC_MADPRED_E0227 |
---|
| 67 | class TAppEncTop; |
---|
| 68 | #endif |
---|
[2] | 69 | /// encoder class |
---|
| 70 | class TEncTop : public TEncCfg |
---|
| 71 | { |
---|
| 72 | private: |
---|
| 73 | // picture |
---|
| 74 | Int m_iPOCLast; ///< time index (POC) |
---|
| 75 | Int m_iNumPicRcvd; ///< number of received pictures |
---|
| 76 | UInt m_uiNumAllPicCoded; ///< number of coded pictures |
---|
| 77 | TComList<TComPic*> m_cListPic; ///< dynamic list of pictures |
---|
[56] | 78 | |
---|
[608] | 79 | #if H_MV |
---|
| 80 | TComPicLists* m_ivPicLists; ///< access to picture lists of other layers |
---|
| 81 | #endif |
---|
[1084] | 82 | #if H_3D_IC |
---|
[1066] | 83 | Int *m_aICEnableCandidate; |
---|
| 84 | Int *m_aICEnableNum; |
---|
| 85 | #endif |
---|
[2] | 86 | // encoder search |
---|
| 87 | TEncSearch m_cSearch; ///< encoder search class |
---|
[872] | 88 | //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder |
---|
[56] | 89 | TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder |
---|
[2] | 90 | // coding tool |
---|
| 91 | TComTrQuant m_cTrQuant; ///< transform & quantization class |
---|
| 92 | TComLoopFilter m_cLoopFilter; ///< deblocking filter class |
---|
[56] | 93 | TEncSampleAdaptiveOffset m_cEncSAO; ///< sample adaptive offset class |
---|
[2] | 94 | TEncEntropy m_cEntropyCoder; ///< entropy encoder |
---|
| 95 | TEncCavlc m_cCavlcCoder; ///< CAVLC encoder |
---|
| 96 | TEncSbac m_cSbacCoder; ///< SBAC encoder |
---|
| 97 | TEncBinCABAC m_cBinCoderCABAC; ///< bin coder CABAC |
---|
[56] | 98 | TEncSbac* m_pcSbacCoders; ///< SBAC encoders (to encode substreams ) |
---|
| 99 | TEncBinCABAC* m_pcBinCoderCABACs; ///< bin coders CABAC (one per substream) |
---|
| 100 | |
---|
[2] | 101 | // processing unit |
---|
[56] | 102 | TEncGOP m_cGOPEncoder; ///< GOP encoder |
---|
[2] | 103 | TEncSlice m_cSliceEncoder; ///< slice encoder |
---|
| 104 | TEncCu m_cCuEncoder; ///< CU encoder |
---|
| 105 | // SPS |
---|
| 106 | TComSPS m_cSPS; ///< SPS |
---|
| 107 | TComPPS m_cPPS; ///< PPS |
---|
| 108 | // RD cost computation |
---|
| 109 | TComBitCounter m_cBitCounter; ///< bit counter for RD optimization |
---|
| 110 | TComRdCost m_cRdCost; ///< RD cost computation class |
---|
| 111 | TEncSbac*** m_pppcRDSbacCoder; ///< temporal storage for RD computation |
---|
| 112 | TEncSbac m_cRDGoOnSbacCoder; ///< going on SBAC model for RD stage |
---|
[56] | 113 | #if FAST_BIT_EST |
---|
| 114 | TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
| 115 | TEncBinCABACCounter m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
| 116 | #else |
---|
[2] | 117 | TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation |
---|
| 118 | TEncBinCABAC m_cRDGoOnBinCoderCABAC; ///< going on bin coder CABAC for RD stage |
---|
[56] | 119 | #endif |
---|
| 120 | Int m_iNumSubstreams; ///< # of top-level elements allocated. |
---|
| 121 | TComBitCounter* m_pcBitCounters; ///< bit counters for RD optimization per substream |
---|
| 122 | TComRdCost* m_pcRdCosts; ///< RD cost computation class per substream |
---|
| 123 | TEncSbac**** m_ppppcRDSbacCoders; ///< temporal storage for RD computation per substream |
---|
| 124 | TEncSbac* m_pcRDGoOnSbacCoders; ///< going on SBAC model for RD stage per substream |
---|
| 125 | TEncBinCABAC**** m_ppppcBinCodersCABAC; ///< temporal CABAC state storage for RD computation per substream |
---|
| 126 | TEncBinCABAC* m_pcRDGoOnBinCodersCABAC; ///< going on bin coder CABAC for RD stage per substream |
---|
[2] | 127 | |
---|
[56] | 128 | // quality control |
---|
| 129 | TEncPreanalyzer m_cPreanalyzer; ///< image characteristics analyzer for TM5-step3-like adaptive QP |
---|
| 130 | |
---|
| 131 | TComScalingList m_scalingList; ///< quantization matrix information |
---|
[608] | 132 | TEncRateCtrl m_cRateCtrl; ///< Rate control class |
---|
[655] | 133 | |
---|
| 134 | #if KWU_RC_MADPRED_E0227 |
---|
| 135 | TAppEncTop* m_pcTAppEncTop; |
---|
| 136 | TAppComCamPara* m_cCamParam; |
---|
| 137 | #endif |
---|
[608] | 138 | |
---|
| 139 | #if H_MV |
---|
[56] | 140 | TEncAnalyze m_cAnalyzeAll; |
---|
| 141 | TEncAnalyze m_cAnalyzeI; |
---|
| 142 | TEncAnalyze m_cAnalyzeP; |
---|
[608] | 143 | TEncAnalyze m_cAnalyzeB; |
---|
| 144 | #endif |
---|
[2] | 145 | protected: |
---|
| 146 | Void xGetNewPicBuffer ( TComPic*& rpcPic ); ///< get picture buffer which will be processed |
---|
| 147 | Void xInitSPS (); ///< initialize SPS from encoder options |
---|
| 148 | Void xInitPPS (); ///< initialize PPS from encoder options |
---|
[56] | 149 | |
---|
| 150 | Void xInitPPSforTiles (); |
---|
[655] | 151 | Void xInitRPS (Bool isFieldCoding); ///< initialize PPS from encoder options |
---|
[1066] | 152 | #if H_MV |
---|
[2] | 153 | |
---|
[1066] | 154 | template <class T> Void xDelete( Bool ar, T inArray ) |
---|
| 155 | { |
---|
| 156 | if( inArray != NULL) |
---|
| 157 | { |
---|
| 158 | if ( ar ) |
---|
| 159 | { |
---|
| 160 | delete[] inArray; |
---|
| 161 | } |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | delete inArray; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | template <class T> Void xDelete( Bool ar, T inArray, Int idx1 ) |
---|
| 170 | { |
---|
| 171 | if( inArray != NULL) |
---|
| 172 | { |
---|
| 173 | xDelete( ar, inArray[idx1]); |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | template <class T> Void xDelete( Bool ar, T inArray, Int idx1, Int idx2 ) |
---|
| 178 | { |
---|
| 179 | if( inArray != NULL ) |
---|
| 180 | { |
---|
| 181 | xDelete( ar, inArray[idx1], idx2 ); |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | template <class T> Void xDelete( Bool ar, T inArray, Int idx1, Int idx2, Int idx3 ) |
---|
| 186 | { |
---|
| 187 | if( inArray != NULL ) |
---|
| 188 | { |
---|
| 189 | xDelete( ar, inArray[idx1], idx2, idx3 ); |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | #endif |
---|
[2] | 194 | public: |
---|
| 195 | TEncTop(); |
---|
| 196 | virtual ~TEncTop(); |
---|
[56] | 197 | |
---|
[2] | 198 | Void create (); |
---|
| 199 | Void destroy (); |
---|
[655] | 200 | #if KWU_RC_MADPRED_E0227 |
---|
| 201 | Void init ( TAppEncTop* pcTAppEncTop, Bool isFieldCoding ); |
---|
| 202 | #else |
---|
| 203 | Void init (Bool isFieldCoding); |
---|
| 204 | #endif |
---|
| 205 | |
---|
[608] | 206 | #if H_MV |
---|
| 207 | TComPicLists* getIvPicLists() { return m_ivPicLists; } |
---|
| 208 | #endif |
---|
[1084] | 209 | #if H_3D_IC |
---|
| 210 | Int* getICEnableCandidate() { return m_aICEnableCandidate; } |
---|
| 211 | Int* getICEnableNum() { return m_aICEnableNum; } |
---|
[1066] | 212 | #endif |
---|
[2] | 213 | Void deletePicBuffer (); |
---|
| 214 | |
---|
[56] | 215 | Void createWPPCoders(Int iNumSubstreams); |
---|
| 216 | |
---|
[608] | 217 | #if H_MV |
---|
| 218 | Void initNewPic(TComPicYuv* pcPicYuvOrg); |
---|
| 219 | #endif |
---|
[2] | 220 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 221 | // member access functions |
---|
| 222 | // ------------------------------------------------------------------------------------------------------------------- |
---|
[56] | 223 | |
---|
[2] | 224 | TComList<TComPic*>* getListPic () { return &m_cListPic; } |
---|
| 225 | TEncSearch* getPredSearch () { return &m_cSearch; } |
---|
[56] | 226 | |
---|
[2] | 227 | TComTrQuant* getTrQuant () { return &m_cTrQuant; } |
---|
| 228 | TComLoopFilter* getLoopFilter () { return &m_cLoopFilter; } |
---|
[56] | 229 | TEncSampleAdaptiveOffset* getSAO () { return &m_cEncSAO; } |
---|
| 230 | TEncGOP* getGOPEncoder () { return &m_cGOPEncoder; } |
---|
[2] | 231 | TEncSlice* getSliceEncoder () { return &m_cSliceEncoder; } |
---|
| 232 | TEncCu* getCuEncoder () { return &m_cCuEncoder; } |
---|
| 233 | TEncEntropy* getEntropyCoder () { return &m_cEntropyCoder; } |
---|
| 234 | TEncCavlc* getCavlcCoder () { return &m_cCavlcCoder; } |
---|
| 235 | TEncSbac* getSbacCoder () { return &m_cSbacCoder; } |
---|
| 236 | TEncBinCABAC* getBinCABAC () { return &m_cBinCoderCABAC; } |
---|
[56] | 237 | TEncSbac* getSbacCoders () { return m_pcSbacCoders; } |
---|
| 238 | TEncBinCABAC* getBinCABACs () { return m_pcBinCoderCABACs; } |
---|
| 239 | |
---|
[2] | 240 | TComBitCounter* getBitCounter () { return &m_cBitCounter; } |
---|
| 241 | TComRdCost* getRdCost () { return &m_cRdCost; } |
---|
| 242 | TEncSbac*** getRDSbacCoder () { return m_pppcRDSbacCoder; } |
---|
| 243 | TEncSbac* getRDGoOnSbacCoder () { return &m_cRDGoOnSbacCoder; } |
---|
[56] | 244 | TComBitCounter* getBitCounters () { return m_pcBitCounters; } |
---|
| 245 | TComRdCost* getRdCosts () { return m_pcRdCosts; } |
---|
| 246 | TEncSbac**** getRDSbacCoders () { return m_ppppcRDSbacCoders; } |
---|
| 247 | TEncSbac* getRDGoOnSbacCoders () { return m_pcRDGoOnSbacCoders; } |
---|
[608] | 248 | TEncRateCtrl* getRateCtrl () { return &m_cRateCtrl; } |
---|
[655] | 249 | #if KWU_RC_MADPRED_E0227 |
---|
| 250 | TAppEncTop* getEncTop () { return m_pcTAppEncTop; } |
---|
| 251 | TAppComCamPara* getCamParam() { return m_cCamParam;} |
---|
| 252 | Void setCamParam(TAppComCamPara * pCamparam) { m_cCamParam = pCamparam;} |
---|
| 253 | #endif |
---|
[56] | 254 | TComSPS* getSPS () { return &m_cSPS; } |
---|
| 255 | TComPPS* getPPS () { return &m_cPPS; } |
---|
[608] | 256 | Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
| 257 | Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ); |
---|
[56] | 258 | TComScalingList* getScalingList () { return &m_scalingList; } |
---|
[608] | 259 | #if H_MV |
---|
[56] | 260 | TEncAnalyze* getAnalyzeAll () { return &m_cAnalyzeAll; } |
---|
| 261 | TEncAnalyze* getAnalyzeI () { return &m_cAnalyzeI; } |
---|
| 262 | TEncAnalyze* getAnalyzeP () { return &m_cAnalyzeP; } |
---|
| 263 | TEncAnalyze* getAnalyzeB () { return &m_cAnalyzeB; } |
---|
| 264 | |
---|
[608] | 265 | Int getNumAllPicCoded () { return m_uiNumAllPicCoded; } |
---|
| 266 | |
---|
| 267 | Int getFrameId (Int iGOPid); |
---|
| 268 | |
---|
| 269 | TComPic* getPic ( Int poc ); |
---|
| 270 | Void setIvPicLists ( TComPicLists* picLists) { m_ivPicLists = picLists; } |
---|
[5] | 271 | #endif |
---|
[1084] | 272 | #if H_3D_IC |
---|
[1066] | 273 | Void setICEnableCandidate ( Int* ICEnableCandidate) { m_aICEnableCandidate = ICEnableCandidate; } |
---|
| 274 | Void setICEnableNum ( Int* ICEnableNum) { m_aICEnableNum = ICEnableNum; } |
---|
| 275 | #endif |
---|
[2] | 276 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 277 | // encoder function |
---|
| 278 | // ------------------------------------------------------------------------------------------------------------------- |
---|
| 279 | |
---|
| 280 | /// encode several number of pictures until end-of-sequence |
---|
[608] | 281 | #if H_MV |
---|
| 282 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded , Int gopId ); |
---|
[655] | 283 | |
---|
| 284 | /// encode several number of pictures until end-of-sequence |
---|
| 285 | Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 286 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff , Int gopId ); |
---|
| 287 | |
---|
[608] | 288 | #else |
---|
| 289 | Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
[655] | 290 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); |
---|
| 291 | /// encode several number of pictures until end-of-sequence |
---|
| 292 | Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 293 | std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff); |
---|
| 294 | |
---|
[608] | 295 | #endif |
---|
| 296 | |
---|
| 297 | #if H_MV |
---|
[655] | 298 | Void printSummary ( Int numAllPicCoded, bool isField ); |
---|
[608] | 299 | #else |
---|
[655] | 300 | Void printSummary(bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); } |
---|
[608] | 301 | #endif |
---|
| 302 | |
---|
| 303 | #if H_3D |
---|
| 304 | Void setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset ); |
---|
| 305 | #endif |
---|
[56] | 306 | }; |
---|
[2] | 307 | |
---|
[56] | 308 | //! \} |
---|
[2] | 309 | |
---|
| 310 | #endif // __TENCTOP__ |
---|