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 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
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 TEncSbac.h |
---|
35 | \brief Context-adaptive entropy encoder class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TENCSBAC__ |
---|
39 | #define __TENCSBAC__ |
---|
40 | |
---|
41 | #if _MSC_VER > 1000 |
---|
42 | #pragma once |
---|
43 | #endif // _MSC_VER > 1000 |
---|
44 | |
---|
45 | #include "TLibCommon/TComBitStream.h" |
---|
46 | #include "TLibCommon/ContextTables.h" |
---|
47 | #include "TLibCommon/ContextModel.h" |
---|
48 | #include "TLibCommon/ContextModel3DBuffer.h" |
---|
49 | #include "TEncEntropy.h" |
---|
50 | #include "TEncBinCoder.h" |
---|
51 | #include "TEncBinCoderCABAC.h" |
---|
52 | #if FAST_BIT_EST |
---|
53 | #include "TEncBinCoderCABACCounter.h" |
---|
54 | #endif |
---|
55 | |
---|
56 | class TEncTop; |
---|
57 | |
---|
58 | //! \ingroup TLibEncoder |
---|
59 | //! \{ |
---|
60 | |
---|
61 | // ==================================================================================================================== |
---|
62 | // Class definition |
---|
63 | // ==================================================================================================================== |
---|
64 | |
---|
65 | /// SBAC encoder class |
---|
66 | class TEncSbac : public TEncEntropyIf |
---|
67 | { |
---|
68 | public: |
---|
69 | TEncSbac(); |
---|
70 | virtual ~TEncSbac(); |
---|
71 | |
---|
72 | Void init ( TEncBinIf* p ) { m_pcBinIf = p; } |
---|
73 | Void uninit () { m_pcBinIf = 0; } |
---|
74 | |
---|
75 | // Virtual list |
---|
76 | Void resetEntropy (); |
---|
77 | Void determineCabacInitIdx (); |
---|
78 | Void setBitstream ( TComBitIf* p ) { m_pcBitIf = p; m_pcBinIf->init( p ); } |
---|
79 | Void setSlice ( TComSlice* p ) { m_pcSlice = p; } |
---|
80 | // SBAC RD |
---|
81 | Void resetCoeffCost () { m_uiCoeffCost = 0; } |
---|
82 | UInt getCoeffCost () { return m_uiCoeffCost; } |
---|
83 | |
---|
84 | Void load ( TEncSbac* pScr ); |
---|
85 | Void loadIntraDirModeLuma ( TEncSbac* pScr ); |
---|
86 | #if H_3D_DIM |
---|
87 | Void loadIntraDepthMode ( TEncSbac* pScr ); |
---|
88 | #endif |
---|
89 | Void store ( TEncSbac* pDest ); |
---|
90 | Void loadContexts ( TEncSbac* pScr ); |
---|
91 | Void resetBits () { m_pcBinIf->resetBits(); m_pcBitIf->resetBits(); } |
---|
92 | UInt getNumberOfWrittenBits () { return m_pcBinIf->getNumWrittenBits(); } |
---|
93 | //--SBAC RD |
---|
94 | |
---|
95 | Void codeVPS ( TComVPS* pcVPS ); |
---|
96 | #if !H_3D |
---|
97 | Void codeSPS ( TComSPS* pcSPS ); |
---|
98 | #else |
---|
99 | Void codeSPS ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag ); |
---|
100 | #endif |
---|
101 | Void codePPS ( TComPPS* pcPPS ); |
---|
102 | Void codeSliceHeader ( TComSlice* pcSlice ); |
---|
103 | Void codeTilesWPPEntryPoint( TComSlice* pSlice ); |
---|
104 | Void codeTerminatingBit ( UInt uilsLast ); |
---|
105 | Void codeSliceFinish (); |
---|
106 | Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ); |
---|
107 | Void codeSaoMerge ( UInt uiCode ); |
---|
108 | Void codeSaoTypeIdx ( UInt uiCode); |
---|
109 | Void codeSaoUflc ( UInt uiLength, UInt uiCode ); |
---|
110 | Void codeSAOSign ( UInt uiCode); //<! code SAO offset sign |
---|
111 | Void codeScalingList ( TComScalingList* /*scalingList*/ ){ assert (0); return;}; |
---|
112 | |
---|
113 | private: |
---|
114 | Void xWriteUnarySymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ); |
---|
115 | Void xWriteUnaryMaxSymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol ); |
---|
116 | Void xWriteEpExGolomb ( UInt uiSymbol, UInt uiCount ); |
---|
117 | Void xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam ); |
---|
118 | #if H_3D_DIM |
---|
119 | Void xWriteExGolombLevel ( UInt uiSymbol, ContextModel& rcSCModel ); |
---|
120 | Void xCodeDimDeltaDC ( Pel valDeltaDC, UInt dimType ); |
---|
121 | #if H_3D_DIM_DMM |
---|
122 | Void xCodeDmm1WedgeIdx ( UInt uiTabIdx, Int iNumBit ); |
---|
123 | #if !SEC_DMM2_E0146 |
---|
124 | Void xCodeDmm2Offset ( Int iOffset ); |
---|
125 | #endif |
---|
126 | Void xCodeDmm3WedgeIdx ( UInt uiIntraIdx, Int iNumBit ); |
---|
127 | #endif |
---|
128 | #if H_3D_DIM_RBC |
---|
129 | Void xCodeRbcEdge ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
130 | #endif |
---|
131 | #if H_3D_DIM_SDC |
---|
132 | Void xCodeSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ); |
---|
133 | #endif |
---|
134 | #endif |
---|
135 | |
---|
136 | Void xCopyFrom ( TEncSbac* pSrc ); |
---|
137 | Void xCopyContextsFrom ( TEncSbac* pSrc ); |
---|
138 | |
---|
139 | Void codeDFFlag( UInt /*uiCode*/, const Char* /*pSymbolName*/ ) {printf("Not supported in codeDFFlag()\n"); assert(0); exit(1);}; |
---|
140 | Void codeDFSvlc( Int /*iCode*/, const Char* /*pSymbolName*/ ) {printf("Not supported in codeDFSvlc()\n"); assert(0); exit(1);}; |
---|
141 | |
---|
142 | protected: |
---|
143 | TComBitIf* m_pcBitIf; |
---|
144 | TComSlice* m_pcSlice; |
---|
145 | TEncBinIf* m_pcBinIf; |
---|
146 | //SBAC RD |
---|
147 | UInt m_uiCoeffCost; |
---|
148 | |
---|
149 | //--Adaptive loop filter |
---|
150 | |
---|
151 | public: |
---|
152 | Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
153 | Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
154 | Void codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
155 | Void codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
156 | #if H_3D_ARP |
---|
157 | Void codeARPW ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
158 | #endif |
---|
159 | #if H_3D_IC |
---|
160 | Void codeICFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
161 | #endif |
---|
162 | Void codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
163 | Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
164 | |
---|
165 | Void codePartSize ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
166 | Void codePredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
167 | Void codeIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
168 | Void codeTransformSubdivFlag ( UInt uiSymbol, UInt uiCtx ); |
---|
169 | Void codeQtCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ); |
---|
170 | Void codeQtRootCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
171 | Void codeQtCbfZero ( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ); |
---|
172 | Void codeQtRootCbfZero ( TComDataCU* pcCU ); |
---|
173 | Void codeIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple); |
---|
174 | |
---|
175 | Void codeIntraDirChroma ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
176 | |
---|
177 | #if H_3D_DIM |
---|
178 | Void codeIntraDepth ( TComDataCU* pcCU, UInt absPartIdx ); |
---|
179 | Void codeIntraDepthMode ( TComDataCU* pcCU, UInt absPartIdx ); |
---|
180 | #endif |
---|
181 | |
---|
182 | Void codeInterDir ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
183 | Void codeRefFrmIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
184 | Void codeMvd ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
185 | |
---|
186 | Void codeDeltaQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
187 | |
---|
188 | Void codeLastSignificantXY ( UInt uiPosX, UInt uiPosY, Int width, Int height, TextType eTType, UInt uiScanIdx ); |
---|
189 | Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ); |
---|
190 | void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ); |
---|
191 | |
---|
192 | // ------------------------------------------------------------------------------------------------------------------- |
---|
193 | // for RD-optimizatioon |
---|
194 | // ------------------------------------------------------------------------------------------------------------------- |
---|
195 | |
---|
196 | Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType); |
---|
197 | Void estCBFBit ( estBitsSbacStruct* pcEstBitsSbac ); |
---|
198 | Void estSignificantCoeffGroupMapBit( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ); |
---|
199 | Void estSignificantMapBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType ); |
---|
200 | Void estSignificantCoefficientsBit ( estBitsSbacStruct* pcEstBitsSbac, TextType eTType ); |
---|
201 | |
---|
202 | Void updateContextTables ( SliceType eSliceType, Int iQp, Bool bExecuteFinish=true ); |
---|
203 | Void updateContextTables ( SliceType eSliceType, Int iQp ) { this->updateContextTables( eSliceType, iQp, true); }; |
---|
204 | |
---|
205 | TEncBinIf* getEncBinIf() { return m_pcBinIf; } |
---|
206 | private: |
---|
207 | UInt m_uiLastQp; |
---|
208 | |
---|
209 | ContextModel m_contextModels[MAX_NUM_CTX_MOD]; |
---|
210 | Int m_numContextModels; |
---|
211 | ContextModel3DBuffer m_cCUSplitFlagSCModel; |
---|
212 | ContextModel3DBuffer m_cCUSkipFlagSCModel; |
---|
213 | ContextModel3DBuffer m_cCUMergeFlagExtSCModel; |
---|
214 | ContextModel3DBuffer m_cCUMergeIdxExtSCModel; |
---|
215 | #if H_3D_ARP |
---|
216 | ContextModel3DBuffer m_cCUPUARPWSCModel; |
---|
217 | #endif |
---|
218 | #if H_3D_IC |
---|
219 | ContextModel3DBuffer m_cCUICFlagSCModel; |
---|
220 | #endif |
---|
221 | ContextModel3DBuffer m_cCUPartSizeSCModel; |
---|
222 | ContextModel3DBuffer m_cCUPredModeSCModel; |
---|
223 | ContextModel3DBuffer m_cCUIntraPredSCModel; |
---|
224 | ContextModel3DBuffer m_cCUChromaPredSCModel; |
---|
225 | ContextModel3DBuffer m_cCUDeltaQpSCModel; |
---|
226 | ContextModel3DBuffer m_cCUInterDirSCModel; |
---|
227 | ContextModel3DBuffer m_cCURefPicSCModel; |
---|
228 | ContextModel3DBuffer m_cCUMvdSCModel; |
---|
229 | ContextModel3DBuffer m_cCUQtCbfSCModel; |
---|
230 | ContextModel3DBuffer m_cCUTransSubdivFlagSCModel; |
---|
231 | ContextModel3DBuffer m_cCUQtRootCbfSCModel; |
---|
232 | |
---|
233 | ContextModel3DBuffer m_cCUSigCoeffGroupSCModel; |
---|
234 | ContextModel3DBuffer m_cCUSigSCModel; |
---|
235 | ContextModel3DBuffer m_cCuCtxLastX; |
---|
236 | ContextModel3DBuffer m_cCuCtxLastY; |
---|
237 | ContextModel3DBuffer m_cCUOneSCModel; |
---|
238 | ContextModel3DBuffer m_cCUAbsSCModel; |
---|
239 | |
---|
240 | ContextModel3DBuffer m_cMVPIdxSCModel; |
---|
241 | |
---|
242 | ContextModel3DBuffer m_cCUAMPSCModel; |
---|
243 | ContextModel3DBuffer m_cSaoMergeSCModel; |
---|
244 | ContextModel3DBuffer m_cSaoTypeIdxSCModel; |
---|
245 | ContextModel3DBuffer m_cTransformSkipSCModel; |
---|
246 | ContextModel3DBuffer m_CUTransquantBypassFlagSCModel; |
---|
247 | |
---|
248 | #if H_3D_DIM |
---|
249 | ContextModel3DBuffer m_cDepthIntraModeSCModel; |
---|
250 | ContextModel3DBuffer m_cDdcFlagSCModel; |
---|
251 | ContextModel3DBuffer m_cDdcDataSCModel; |
---|
252 | #if H_3D_DIM_DMM |
---|
253 | ContextModel3DBuffer m_cDmm1DataSCModel; |
---|
254 | #if !SEC_DMM2_E0146 |
---|
255 | ContextModel3DBuffer m_cDmm2DataSCModel; |
---|
256 | #endif |
---|
257 | ContextModel3DBuffer m_cDmm3DataSCModel; |
---|
258 | #endif |
---|
259 | #if H_3D_DIM_RBC |
---|
260 | ContextModel3DBuffer m_cRbcDataSCModel; |
---|
261 | #endif |
---|
262 | #if H_3D_DIM_SDC |
---|
263 | ContextModel3DBuffer m_cSDCResidualFlagSCModel; |
---|
264 | ContextModel3DBuffer m_cSDCResidualSCModel; |
---|
265 | #endif |
---|
266 | #endif |
---|
267 | }; |
---|
268 | |
---|
269 | //! \} |
---|
270 | |
---|
271 | #endif // !defined(AFX_TENCSBAC_H__DDA7CDC4_EDE3_4015_9D32_2156249C82AA__INCLUDED_) |
---|