[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 |
---|
[916] | 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 TEncCu.h |
---|
| 35 | \brief Coding Unit (CU) encoder class (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __TENCCU__ |
---|
| 39 | #define __TENCCU__ |
---|
| 40 | |
---|
| 41 | // Include files |
---|
| 42 | #include "TLibCommon/CommonDef.h" |
---|
| 43 | #include "TLibCommon/TComYuv.h" |
---|
| 44 | #include "TLibCommon/TComPrediction.h" |
---|
| 45 | #include "TLibCommon/TComTrQuant.h" |
---|
| 46 | #include "TLibCommon/TComBitCounter.h" |
---|
| 47 | #include "TLibCommon/TComDataCU.h" |
---|
| 48 | |
---|
| 49 | #include "TEncEntropy.h" |
---|
| 50 | #include "TEncSearch.h" |
---|
| 51 | #include "TEncRateCtrl.h" |
---|
| 52 | //! \ingroup TLibEncoder |
---|
| 53 | //! \{ |
---|
| 54 | |
---|
| 55 | class TEncTop; |
---|
| 56 | class TEncSbac; |
---|
| 57 | class TEncCavlc; |
---|
| 58 | class TEncSlice; |
---|
| 59 | |
---|
| 60 | // ==================================================================================================================== |
---|
| 61 | // Class definition |
---|
| 62 | // ==================================================================================================================== |
---|
| 63 | |
---|
| 64 | /// CU encoder class |
---|
| 65 | class TEncCu |
---|
| 66 | { |
---|
| 67 | private: |
---|
[916] | 68 | |
---|
[313] | 69 | TComDataCU** m_ppcBestCU; ///< Best CUs in each depth |
---|
| 70 | TComDataCU** m_ppcTempCU; ///< Temporary CUs in each depth |
---|
| 71 | UChar m_uhTotalDepth; |
---|
[916] | 72 | |
---|
[313] | 73 | TComYuv** m_ppcPredYuvBest; ///< Best Prediction Yuv for each depth |
---|
| 74 | TComYuv** m_ppcResiYuvBest; ///< Best Residual Yuv for each depth |
---|
| 75 | TComYuv** m_ppcRecoYuvBest; ///< Best Reconstruction Yuv for each depth |
---|
| 76 | TComYuv** m_ppcPredYuvTemp; ///< Temporary Prediction Yuv for each depth |
---|
| 77 | TComYuv** m_ppcResiYuvTemp; ///< Temporary Residual Yuv for each depth |
---|
| 78 | TComYuv** m_ppcRecoYuvTemp; ///< Temporary Reconstruction Yuv for each depth |
---|
| 79 | TComYuv** m_ppcOrigYuv; ///< Original Yuv for each depth |
---|
[916] | 80 | |
---|
[313] | 81 | // Data : encoder control |
---|
| 82 | Bool m_bEncodeDQP; |
---|
[916] | 83 | Bool m_CodeChromaQpAdjFlag; |
---|
| 84 | Int m_ChromaQpAdjIdc; |
---|
| 85 | |
---|
[313] | 86 | // Access channel |
---|
| 87 | TEncCfg* m_pcEncCfg; |
---|
| 88 | TEncSearch* m_pcPredSearch; |
---|
| 89 | TComTrQuant* m_pcTrQuant; |
---|
| 90 | TComRdCost* m_pcRdCost; |
---|
[916] | 91 | |
---|
[313] | 92 | TEncEntropy* m_pcEntropyCoder; |
---|
| 93 | TEncBinCABAC* m_pcBinCABAC; |
---|
[916] | 94 | |
---|
[313] | 95 | // SBAC RD |
---|
| 96 | TEncSbac*** m_pppcRDSbacCoder; |
---|
| 97 | TEncSbac* m_pcRDGoOnSbacCoder; |
---|
| 98 | TEncRateCtrl* m_pcRateCtrl; |
---|
[540] | 99 | |
---|
[595] | 100 | #if SVC_EXTENSION |
---|
| 101 | TEncTop** m_ppcTEncTop; |
---|
[494] | 102 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 103 | Bool m_disableILP; |
---|
| 104 | #endif |
---|
[595] | 105 | #endif //SVC_EXTENSION |
---|
[313] | 106 | public: |
---|
| 107 | /// copy parameters from encoder class |
---|
| 108 | Void init ( TEncTop* pcEncTop ); |
---|
[916] | 109 | |
---|
[313] | 110 | /// create internal buffers |
---|
[916] | 111 | Void create ( UChar uhTotalDepth, UInt iMaxWidth, UInt iMaxHeight, ChromaFormat chromaFormat ); |
---|
| 112 | |
---|
[313] | 113 | /// destroy internal buffers |
---|
| 114 | Void destroy (); |
---|
[916] | 115 | |
---|
| 116 | /// CTU analysis function |
---|
| 117 | Void compressCtu ( TComDataCU* pCtu ); |
---|
| 118 | |
---|
| 119 | /// CTU encoding function |
---|
| 120 | Void encodeCtu ( TComDataCU* pCtu ); |
---|
| 121 | |
---|
| 122 | Int updateCtuDataISlice ( TComDataCU* pCtu, Int width, Int height ); |
---|
| 123 | |
---|
[313] | 124 | protected: |
---|
| 125 | Void finishCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
| 126 | #if AMP_ENC_SPEEDUP |
---|
[916] | 127 | Void xCompressCU ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug), PartSize eParentPartSize = NUMBER_OF_PART_SIZES ); |
---|
[313] | 128 | #else |
---|
| 129 | Void xCompressCU ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ); |
---|
| 130 | #endif |
---|
| 131 | Void xEncodeCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
[916] | 132 | |
---|
[313] | 133 | Int xComputeQP ( TComDataCU* pcCU, UInt uiDepth ); |
---|
[916] | 134 | Void xCheckBestMode ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sParent) DEBUG_STRING_FN_DECLARE(sTest) DEBUG_STRING_PASS_INTO(Bool bAddSizeInfo=true)); |
---|
[540] | 135 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
[916] | 136 | Void xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode, Bool bUseSkip=false); |
---|
[540] | 137 | #else |
---|
[916] | 138 | Void xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode ); |
---|
[540] | 139 | #endif |
---|
[313] | 140 | |
---|
| 141 | #if AMP_MRG |
---|
[916] | 142 | Void xCheckRDCostInter ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG = false ); |
---|
[313] | 143 | #else |
---|
| 144 | Void xCheckRDCostInter ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ); |
---|
| 145 | #endif |
---|
[916] | 146 | |
---|
| 147 | Void xCheckRDCostIntra ( TComDataCU *&rpcBestCU, |
---|
| 148 | TComDataCU *&rpcTempCU, |
---|
| 149 | Double &cost, |
---|
| 150 | PartSize ePartSize |
---|
| 151 | DEBUG_STRING_FN_DECLARE(sDebug) |
---|
| 152 | ); |
---|
| 153 | |
---|
[313] | 154 | Void xCheckDQP ( TComDataCU* pcCU ); |
---|
[916] | 155 | |
---|
[313] | 156 | Void xCheckIntraPCM ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ); |
---|
| 157 | Void xCopyAMVPInfo ( AMVPInfo* pSrc, AMVPInfo* pDst ); |
---|
| 158 | Void xCopyYuv2Pic (TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ); |
---|
| 159 | Void xCopyYuv2Tmp ( UInt uhPartUnitIdx, UInt uiDepth ); |
---|
| 160 | |
---|
| 161 | Bool getdQPFlag () { return m_bEncodeDQP; } |
---|
| 162 | Void setdQPFlag ( Bool b ) { m_bEncodeDQP = b; } |
---|
| 163 | |
---|
[916] | 164 | Bool getCodeChromaQpAdjFlag() { return m_CodeChromaQpAdjFlag; } |
---|
| 165 | Void setCodeChromaQpAdjFlag( Bool b ) { m_CodeChromaQpAdjFlag = b; } |
---|
| 166 | |
---|
[313] | 167 | #if ADAPTIVE_QP_SELECTION |
---|
| 168 | // Adaptive reconstruction level (ARL) statistics collection functions |
---|
[916] | 169 | Void xCtuCollectARLStats(TComDataCU* pCtu); |
---|
| 170 | Int xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ); |
---|
[313] | 171 | #endif |
---|
| 172 | |
---|
[916] | 173 | #if AMP_ENC_SPEEDUP |
---|
[313] | 174 | #if AMP_MRG |
---|
[916] | 175 | Void deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver); |
---|
[313] | 176 | #else |
---|
[916] | 177 | Void deriveTestModeAMP (TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver); |
---|
[313] | 178 | #endif |
---|
| 179 | #endif |
---|
| 180 | |
---|
[916] | 181 | Void xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ); |
---|
[595] | 182 | |
---|
[313] | 183 | #if SVC_EXTENSION |
---|
| 184 | TEncTop* getLayerEnc(UInt LayerId) {return m_ppcTEncTop[LayerId]; } |
---|
[595] | 185 | #if ENCODER_FAST_MODE |
---|
| 186 | Void xCheckRDCostILRUni ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId); |
---|
| 187 | #endif |
---|
| 188 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 189 | Bool xCheckTileSetConstraint( TComDataCU*& rpcCU ); |
---|
| 190 | Void xVerifyTileSetConstraint( TComDataCU*& rpcCU ); |
---|
| 191 | #endif |
---|
| 192 | #endif //SVC_EXTENSION |
---|
[313] | 193 | }; |
---|
| 194 | |
---|
| 195 | //! \} |
---|
| 196 | |
---|
| 197 | #endif // __TENCMB__ |
---|