[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 |
---|
| 4 | * granted under this license. |
---|
| 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 TEncEntropy.h |
---|
| 35 | \brief entropy encoder class (header) |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __TENCENTROPY__ |
---|
| 39 | #define __TENCENTROPY__ |
---|
| 40 | |
---|
| 41 | #include "TLibCommon/TComSlice.h" |
---|
| 42 | #include "TLibCommon/TComDataCU.h" |
---|
| 43 | #include "TLibCommon/TComBitStream.h" |
---|
| 44 | #include "TLibCommon/ContextModel.h" |
---|
| 45 | #include "TLibCommon/TComPic.h" |
---|
| 46 | #include "TLibCommon/TComTrQuant.h" |
---|
| 47 | #include "TLibCommon/TComSampleAdaptiveOffset.h" |
---|
| 48 | |
---|
| 49 | class TEncSbac; |
---|
| 50 | class TEncCavlc; |
---|
| 51 | class SEI; |
---|
| 52 | |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | // Class definition |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | |
---|
| 57 | /// entropy encoder pure class |
---|
| 58 | class TEncEntropyIf |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | virtual Void resetEntropy () = 0; |
---|
| 62 | virtual Void determineCabacInitIdx () = 0; |
---|
| 63 | virtual Void setBitstream ( TComBitIf* p ) = 0; |
---|
| 64 | virtual Void setSlice ( TComSlice* p ) = 0; |
---|
| 65 | virtual Void resetBits () = 0; |
---|
| 66 | virtual Void resetCoeffCost () = 0; |
---|
| 67 | virtual UInt getNumberOfWrittenBits() = 0; |
---|
| 68 | virtual UInt getCoeffCost () = 0; |
---|
| 69 | |
---|
| 70 | virtual Void codeVPS ( TComVPS* pcVPS ) = 0; |
---|
| 71 | virtual Void codeSPS ( TComSPS* pcSPS ) = 0; |
---|
| 72 | virtual Void codePPS ( TComPPS* pcPPS ) = 0; |
---|
| 73 | virtual Void codeSliceHeader ( TComSlice* pcSlice ) = 0; |
---|
| 74 | |
---|
| 75 | virtual Void codeTilesWPPEntryPoint ( TComSlice* pSlice ) = 0; |
---|
[644] | 76 | #if POC_RESET_IDC_SIGNALLING |
---|
| 77 | virtual Void codeSliceHeaderExtn ( TComSlice* pSlice, Int shBitsWrittenTillNow ) = 0; |
---|
| 78 | #endif |
---|
[313] | 79 | virtual Void codeTerminatingBit ( UInt uilsLast ) = 0; |
---|
| 80 | virtual Void codeSliceFinish () = 0; |
---|
| 81 | virtual Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) = 0; |
---|
| 82 | virtual Void codeScalingList ( TComScalingList* scalingList ) = 0; |
---|
| 83 | |
---|
| 84 | public: |
---|
| 85 | virtual Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 86 | virtual Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 87 | virtual Void codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 88 | virtual Void codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 89 | virtual Void codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0; |
---|
[345] | 90 | |
---|
[313] | 91 | virtual Void codePartSize ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0; |
---|
| 92 | virtual Void codePredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 93 | |
---|
| 94 | virtual Void codeIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 95 | |
---|
| 96 | virtual Void codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) = 0; |
---|
| 97 | virtual Void codeQtCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) = 0; |
---|
| 98 | virtual Void codeQtRootCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 99 | virtual Void codeQtCbfZero ( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) = 0; |
---|
| 100 | virtual Void codeQtRootCbfZero ( TComDataCU* pcCU ) = 0; |
---|
| 101 | virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool isMultiplePU ) = 0; |
---|
| 102 | |
---|
| 103 | virtual Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 104 | virtual Void codeInterDir ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 105 | virtual Void codeRefFrmIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) = 0; |
---|
| 106 | virtual Void codeMvd ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) = 0; |
---|
| 107 | virtual Void codeDeltaQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0; |
---|
| 108 | virtual Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0; |
---|
| 109 | virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0; |
---|
[644] | 110 | #if SVC_EXTENSION |
---|
| 111 | virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false) =0; |
---|
| 112 | #else |
---|
[540] | 113 | virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false) =0; |
---|
[644] | 114 | #endif |
---|
[313] | 115 | virtual Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0; |
---|
| 116 | |
---|
| 117 | virtual Void updateContextTables ( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) = 0; |
---|
| 118 | virtual Void updateContextTables ( SliceType eSliceType, Int iQp ) = 0; |
---|
| 119 | |
---|
| 120 | virtual Void codeDFFlag (UInt uiCode, const Char *pSymbolName) = 0; |
---|
| 121 | virtual Void codeDFSvlc (Int iCode, const Char *pSymbolName) = 0; |
---|
| 122 | |
---|
| 123 | virtual ~TEncEntropyIf() {} |
---|
| 124 | |
---|
| 125 | }; |
---|
| 126 | |
---|
| 127 | /// entropy encoder class |
---|
| 128 | class TEncEntropy |
---|
| 129 | { |
---|
| 130 | private: |
---|
| 131 | UInt m_uiBakAbsPartIdx; |
---|
| 132 | UInt m_uiBakChromaOffset; |
---|
| 133 | UInt m_bakAbsPartIdxCU; |
---|
| 134 | |
---|
| 135 | public: |
---|
| 136 | Void setEntropyCoder ( TEncEntropyIf* e, TComSlice* pcSlice ); |
---|
| 137 | Void setBitstream ( TComBitIf* p ) { m_pcEntropyCoderIf->setBitstream(p); } |
---|
| 138 | Void resetBits () { m_pcEntropyCoderIf->resetBits(); } |
---|
| 139 | Void resetCoeffCost () { m_pcEntropyCoderIf->resetCoeffCost(); } |
---|
| 140 | UInt getNumberOfWrittenBits () { return m_pcEntropyCoderIf->getNumberOfWrittenBits(); } |
---|
| 141 | UInt getCoeffCost () { return m_pcEntropyCoderIf->getCoeffCost(); } |
---|
| 142 | Void resetEntropy () { m_pcEntropyCoderIf->resetEntropy(); } |
---|
| 143 | Void determineCabacInitIdx () { m_pcEntropyCoderIf->determineCabacInitIdx(); } |
---|
| 144 | |
---|
| 145 | Void encodeSliceHeader ( TComSlice* pcSlice ); |
---|
| 146 | Void encodeTilesWPPEntryPoint( TComSlice* pSlice ); |
---|
[644] | 147 | #if POC_RESET_IDC_SIGNALLING |
---|
| 148 | Void encodeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow ); |
---|
| 149 | #endif |
---|
[313] | 150 | Void encodeTerminatingBit ( UInt uiIsLast ); |
---|
| 151 | Void encodeSliceFinish (); |
---|
| 152 | TEncEntropyIf* m_pcEntropyCoderIf; |
---|
| 153 | |
---|
| 154 | public: |
---|
| 155 | Void encodeVPS ( TComVPS* pcVPS); |
---|
| 156 | // SPS |
---|
| 157 | Void encodeSPS ( TComSPS* pcSPS ); |
---|
| 158 | Void encodePPS ( TComPPS* pcPPS ); |
---|
| 159 | Void encodeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false ); |
---|
| 160 | Void encodeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 161 | Void encodeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 162 | Void encodePUWise ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 163 | Void encodeInterDirPU ( TComDataCU* pcSubCU, UInt uiAbsPartIdx ); |
---|
| 164 | Void encodeRefFrmIdxPU ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
| 165 | Void encodeMvdPU ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
| 166 | Void encodeMVPIdxPU ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
| 167 | Void encodeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
| 168 | Void encodeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 169 | Void encodePredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 170 | Void encodePartSize ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false ); |
---|
| 171 | Void encodeIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 172 | Void encodePredInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 173 | Void encodeIntraDirModeLuma ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiplePU = false ); |
---|
| 174 | |
---|
| 175 | Void encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 176 | |
---|
| 177 | Void encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ); |
---|
| 178 | Void encodeQtCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ); |
---|
| 179 | Void encodeQtCbfZero ( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ); |
---|
| 180 | Void encodeQtRootCbfZero ( TComDataCU* pcCU ); |
---|
| 181 | Void encodeQtRootCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
| 182 | Void encodeQP ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false ); |
---|
| 183 | Void updateContextTables ( SliceType eSliceType, Int iQp, Bool bExecuteFinish ) { m_pcEntropyCoderIf->updateContextTables( eSliceType, iQp, bExecuteFinish ); } |
---|
| 184 | Void updateContextTables ( SliceType eSliceType, Int iQp ) { m_pcEntropyCoderIf->updateContextTables( eSliceType, iQp, true ); } |
---|
| 185 | |
---|
| 186 | Void encodeScalingList ( TComScalingList* scalingList ); |
---|
| 187 | |
---|
| 188 | private: |
---|
| 189 | Void xEncodeTransform ( TComDataCU* pcCU,UInt offsetLumaOffset, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ); |
---|
| 190 | public: |
---|
| 191 | Void encodeCoeff ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP ); |
---|
| 192 | |
---|
| 193 | Void encodeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType ); |
---|
| 194 | |
---|
| 195 | Void estimateBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType); |
---|
[644] | 196 | #if SVC_EXTENSION |
---|
| 197 | Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, saoMaxOffsetQVal, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);} |
---|
| 198 | #else |
---|
[540] | 199 | Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);} |
---|
[644] | 200 | #endif |
---|
[313] | 201 | static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ); |
---|
| 202 | |
---|
| 203 | };// END CLASS DEFINITION TEncEntropy |
---|
| 204 | |
---|
| 205 | //! \} |
---|
| 206 | |
---|
| 207 | #endif // __TENCENTROPY__ |
---|
| 208 | |
---|