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-2011, 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 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 | |
---|
35 | |
---|
36 | /** \file TEncCavlc.h |
---|
37 | \brief CAVLC encoder class (header) |
---|
38 | */ |
---|
39 | |
---|
40 | #ifndef __TENCCAVLC__ |
---|
41 | #define __TENCCAVLC__ |
---|
42 | |
---|
43 | #if _MSC_VER > 1000 |
---|
44 | #pragma once |
---|
45 | #endif // _MSC_VER > 1000 |
---|
46 | |
---|
47 | #include "../TLibCommon/CommonDef.h" |
---|
48 | #include "../TLibCommon/TComBitStream.h" |
---|
49 | #include "TEncEntropy.h" |
---|
50 | #if QC_MOD_LCEC |
---|
51 | #include "../TLibCommon/TComRom.h" |
---|
52 | #endif |
---|
53 | |
---|
54 | class TEncTop; |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Class definition |
---|
58 | // ==================================================================================================================== |
---|
59 | |
---|
60 | /// CAVLC encoder class |
---|
61 | class TEncCavlc : public TEncEntropyIf |
---|
62 | { |
---|
63 | private: |
---|
64 | Bool m_bAdaptFlag; |
---|
65 | |
---|
66 | |
---|
67 | public: |
---|
68 | TEncCavlc(); |
---|
69 | virtual ~TEncCavlc(); |
---|
70 | |
---|
71 | protected: |
---|
72 | TComBitIf* m_pcBitIf; |
---|
73 | TComSlice* m_pcSlice; |
---|
74 | UInt m_uiCoeffCost; |
---|
75 | Bool m_bRunLengthCoding; |
---|
76 | UInt m_uiRun; |
---|
77 | Bool m_bAlfCtrl; |
---|
78 | UInt m_uiMaxAlfCtrlDepth; |
---|
79 | UInt m_uiLPTableE4[3][32]; |
---|
80 | UInt m_uiLPTableD4[3][32]; |
---|
81 | #if !CAVLC_COEF_LRG_BLK |
---|
82 | UInt m_uiLPTableE8[10][128]; |
---|
83 | UInt m_uiLPTableD8[10][128]; |
---|
84 | #endif |
---|
85 | UInt m_uiLastPosVlcIndex[10]; |
---|
86 | |
---|
87 | #if LCEC_INTRA_MODE |
---|
88 | #if MTK_DCM_MPM |
---|
89 | UInt m_uiIntraModeTableD17[2][16]; |
---|
90 | UInt m_uiIntraModeTableE17[2][16]; |
---|
91 | |
---|
92 | UInt m_uiIntraModeTableD34[2][33]; |
---|
93 | UInt m_uiIntraModeTableE34[2][33]; |
---|
94 | #else |
---|
95 | UInt m_uiIntraModeTableD17[16]; |
---|
96 | UInt m_uiIntraModeTableE17[16]; |
---|
97 | |
---|
98 | UInt m_uiIntraModeTableD34[33]; |
---|
99 | UInt m_uiIntraModeTableE34[33]; |
---|
100 | #endif |
---|
101 | #endif |
---|
102 | |
---|
103 | #if CAVLC_RQT_CBP |
---|
104 | UInt m_uiCBP_YUV_TableE[4][8]; |
---|
105 | UInt m_uiCBP_YUV_TableD[4][8]; |
---|
106 | UInt m_uiCBP_YS_TableE[2][4]; |
---|
107 | UInt m_uiCBP_YS_TableD[2][4]; |
---|
108 | UInt m_uiCBP_YCS_TableE[2][8]; |
---|
109 | UInt m_uiCBP_YCS_TableD[2][8]; |
---|
110 | UInt m_uiCBP_4Y_TableE[2][15]; |
---|
111 | UInt m_uiCBP_4Y_TableD[2][15]; |
---|
112 | UInt m_uiCBP_4Y_VlcIdx; |
---|
113 | #else |
---|
114 | UInt m_uiCBPTableE[2][8]; |
---|
115 | UInt m_uiCBPTableD[2][8]; |
---|
116 | UInt m_uiBlkCBPTableE[2][15]; |
---|
117 | UInt m_uiBlkCBPTableD[2][15]; |
---|
118 | UInt m_uiCbpVlcIdx[2]; |
---|
119 | UInt m_uiBlkCbpVlcIdx; |
---|
120 | #endif |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | #if MS_LCEC_LOOKUP_TABLE_EXCEPTION |
---|
125 | UInt m_uiMI1TableE[9]; |
---|
126 | UInt m_uiMI1TableD[9]; |
---|
127 | #else |
---|
128 | UInt m_uiMI1TableE[8]; |
---|
129 | UInt m_uiMI1TableD[8]; |
---|
130 | #endif |
---|
131 | UInt m_uiMI2TableE[15]; |
---|
132 | UInt m_uiMI2TableD[15]; |
---|
133 | |
---|
134 | UInt m_uiMITableVlcIdx; |
---|
135 | #if QC_LCEC_INTER_MODE |
---|
136 | UInt m_uiSplitTableE[4][7]; |
---|
137 | UInt m_uiSplitTableD[4][7]; |
---|
138 | #endif |
---|
139 | |
---|
140 | #if CAVLC_COUNTER_ADAPT |
---|
141 | #if CAVLC_RQT_CBP |
---|
142 | UChar m_ucCBP_YUV_TableCounter[4][4]; |
---|
143 | UChar m_ucCBP_4Y_TableCounter[2][2]; |
---|
144 | UChar m_ucCBP_YS_TableCounter[2][3]; |
---|
145 | UChar m_ucCBP_YCS_TableCounter[2][4]; |
---|
146 | UChar m_ucCBP_YUV_TableCounterSum[4]; |
---|
147 | UChar m_ucCBP_4Y_TableCounterSum[2]; |
---|
148 | UChar m_ucCBP_YS_TableCounterSum[2]; |
---|
149 | UChar m_ucCBP_YCS_TableCounterSum[2]; |
---|
150 | #else |
---|
151 | UChar m_ucCBFTableCounter [2][4]; |
---|
152 | UChar m_ucBlkCBPTableCounter [2][2]; |
---|
153 | UChar m_ucCBFTableCounterSum[2]; |
---|
154 | UChar m_ucBlkCBPTableCounterSum[2]; |
---|
155 | #endif |
---|
156 | UChar m_ucMI1TableCounter [4]; |
---|
157 | UChar m_ucSplitTableCounter [4][4]; |
---|
158 | |
---|
159 | UChar m_ucSplitTableCounterSum[4]; |
---|
160 | UChar m_ucMI1TableCounterSum; |
---|
161 | #endif |
---|
162 | |
---|
163 | Void xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart ); |
---|
164 | |
---|
165 | Void xWriteCode ( UInt uiCode, UInt uiLength ); |
---|
166 | Void xWriteUvlc ( UInt uiCode ); |
---|
167 | Void xWriteSvlc ( Int iCode ); |
---|
168 | Void xWriteFlag ( UInt uiCode ); |
---|
169 | Void xWriteEpExGolomb ( UInt uiSymbol, UInt uiCount ); |
---|
170 | Void xWriteExGolombLevel ( UInt uiSymbol ); |
---|
171 | Void xWriteUnaryMaxSymbol ( UInt uiSymbol, UInt uiMaxSymbol ); |
---|
172 | #if !QC_MOD_LCEC_RDOQ |
---|
173 | UInt xLeadingZeros ( UInt uiCode ); |
---|
174 | #endif |
---|
175 | Void xWriteVlc ( UInt uiTableNumber, UInt uiCodeNumber ); |
---|
176 | |
---|
177 | #if CAVLC_COEF_LRG_BLK |
---|
178 | Void xCodeCoeff ( TCoeff* scoeff, Int n, Int blSize); |
---|
179 | #else |
---|
180 | Void xCodeCoeff4x4 ( TCoeff* scoeff, Int iTableNumber ); |
---|
181 | Void xCodeCoeff8x8 ( TCoeff* scoeff, Int iTableNumber ); |
---|
182 | #endif |
---|
183 | |
---|
184 | UInt xConvertToUInt ( Int iValue ) { return ( iValue <= 0) ? -iValue<<1 : (iValue<<1)-1; } |
---|
185 | |
---|
186 | public: |
---|
187 | |
---|
188 | Void resetEntropy (); |
---|
189 | |
---|
190 | #if !CAVLC_COEF_LRG_BLK |
---|
191 | UInt* GetLP8Table(); |
---|
192 | #endif |
---|
193 | UInt* GetLP4Table(); |
---|
194 | #if QC_MOD_LCEC |
---|
195 | UInt* GetLastPosVlcIndexTable(); |
---|
196 | #endif |
---|
197 | Void setBitstream ( TComBitIf* p ) { m_pcBitIf = p; } |
---|
198 | Void setSlice ( TComSlice* p ) { m_pcSlice = p; } |
---|
199 | Bool getAlfCtrl() {return m_bAlfCtrl;} |
---|
200 | UInt getMaxAlfCtrlDepth() {return m_uiMaxAlfCtrlDepth;} |
---|
201 | Void setAlfCtrl(Bool bAlfCtrl) {m_bAlfCtrl = bAlfCtrl;} |
---|
202 | Void setMaxAlfCtrlDepth(UInt uiMaxAlfCtrlDepth) {m_uiMaxAlfCtrlDepth = uiMaxAlfCtrlDepth;} |
---|
203 | Void resetBits () { m_pcBitIf->resetBits(); } |
---|
204 | Void resetCoeffCost () { m_uiCoeffCost = 0; } |
---|
205 | UInt getNumberOfWrittenBits() { return m_pcBitIf->getNumberOfWrittenBits(); } |
---|
206 | UInt getCoeffCost () { return m_uiCoeffCost; } |
---|
207 | |
---|
208 | Void codeNALUnitHeader ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, Bool bOutputFlag = true ); |
---|
209 | |
---|
210 | Void codeSPS ( TComSPS* pcSPS ); |
---|
211 | Void codePPS ( TComPPS* pcPPS ); |
---|
212 | void codeSEI(const SEI&); |
---|
213 | Void codeSliceHeader ( TComSlice* pcSlice ); |
---|
214 | Void codeTerminatingBit ( UInt uilsLast ); |
---|
215 | Void codeSliceFinish (); |
---|
216 | |
---|
217 | Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
218 | Void codeAlfFlag ( UInt uiCode ); |
---|
219 | Void codeAlfUvlc ( UInt uiCode ); |
---|
220 | Void codeAlfSvlc ( Int iCode ); |
---|
221 | Void codeAlfCtrlDepth(); |
---|
222 | #if MTK_SAO |
---|
223 | Void codeAoFlag ( UInt uiCode ); |
---|
224 | Void codeAoUvlc ( UInt uiCode ); |
---|
225 | Void codeAoSvlc ( Int iCode ); |
---|
226 | #endif |
---|
227 | Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
228 | Void codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
229 | Void codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
230 | #if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI || POZNAN_DBMP |
---|
231 | Void codeMergeIndexMV ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
232 | #endif |
---|
233 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
234 | Void codeResPredFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
235 | #endif |
---|
236 | Void codeAlfCtrlFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
237 | #if TSB_ALF_HEADER |
---|
238 | Void codeAlfFlagNum ( UInt uiCode, UInt minValue ); |
---|
239 | Void codeAlfCtrlFlag ( UInt uiSymbol ); |
---|
240 | #endif |
---|
241 | #if QC_LCEC_INTER_MODE |
---|
242 | Void codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ); |
---|
243 | #endif |
---|
244 | Void codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
245 | |
---|
246 | Void codePartSize ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
247 | Void codePredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
248 | |
---|
249 | Void codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ); |
---|
250 | Void codeQtCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ); |
---|
251 | Void codeQtRootCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
252 | |
---|
253 | Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
254 | |
---|
255 | Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
256 | Void codeInterDir ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
257 | Void codeRefFrmIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
258 | Void codeMvd ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); |
---|
259 | |
---|
260 | Void codeDeltaQP ( TComDataCU* pcCU, UInt uiAbsPartIdx ); |
---|
261 | |
---|
262 | Void codeViewIdx ( Int iViewIdx ); |
---|
263 | #if CAVLC_RQT_CBP |
---|
264 | Void codeCbfTrdiv ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
265 | UInt xGetFlagPattern ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); |
---|
266 | #endif |
---|
267 | Void codeCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ); |
---|
268 | Void codeBlockCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiQPartNum, Bool bRD = false); |
---|
269 | |
---|
270 | Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD = false ); |
---|
271 | |
---|
272 | #ifdef WEIGHT_PRED |
---|
273 | Void codeWeightPredTable( TComSlice* pcSlice ); |
---|
274 | #endif |
---|
275 | |
---|
276 | Void estBit (estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType); |
---|
277 | |
---|
278 | Bool getAdaptFlag () { return m_bAdaptFlag; } |
---|
279 | Void setAdaptFlag ( Bool b ) { m_bAdaptFlag = b; } |
---|
280 | }; |
---|
281 | |
---|
282 | #endif // !defined(AFX_TENCCAVLC_H__EE8A0B30_945B_4169_B290_24D3AD52296F__INCLUDED_) |
---|
283 | |
---|