HEVC Test Model (HM)  HM-16.3
TEncSbac.h
Go to the documentation of this file.
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-2015, 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 
38 #ifndef __TENCSBAC__
39 #define __TENCSBAC__
40 
41 #if _MSC_VER > 1000
42 #pragma once
43 #endif // _MSC_VER > 1000
44 
49 #include "TEncEntropy.h"
50 #include "TEncBinCoder.h"
51 #include "TEncBinCoderCABAC.h"
52 #if FAST_BIT_EST
54 #endif
55 
56 class TEncTop;
57 
60 
61 // ====================================================================================================================
62 // Class definition
63 // ====================================================================================================================
64 
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 ();
79  Void setSlice ( TComSlice* p ) { m_pcSlice = p; }
80 
81  Void load ( const TEncSbac* pSrc );
82  Void loadIntraDirMode ( const TEncSbac* pScr, const ChannelType chType );
83  Void store ( TEncSbac* pDest ) const;
84  Void loadContexts ( const TEncSbac* pSrc );
87  //--SBAC RD
88 
89  Void codeVPS ( const TComVPS* pcVPS );
90  Void codeSPS ( const TComSPS* pcSPS );
91  Void codePPS ( const TComPPS* pcPPS );
92  Void codeSliceHeader ( TComSlice* pcSlice );
94  Void codeTerminatingBit ( UInt uilsLast );
96  Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol );
97  Void codeSaoMerge ( UInt uiCode );
98  Void codeSaoTypeIdx ( UInt uiCode);
99  Void codeSaoUflc ( UInt uiLength, UInt uiCode );
100  Void codeSAOSign ( UInt uiCode); //<! code SAO offset sign
101 
102  Void codeSAOOffsetParam(ComponentID compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
103  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
104  , Bool* sliceEnabled
105  , Bool leftMergeAvail
106  , Bool aboveMergeAvail
107  , Bool onlyEstMergeInfo = false
108  );
109 
110 private:
111  Void xWriteUnarySymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset );
112  Void xWriteUnaryMaxSymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol );
113  Void xWriteEpExGolomb ( UInt uiSymbol, UInt uiCount );
114  Void xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType );
115 
116  Void xCopyFrom ( const TEncSbac* pSrc );
117  Void xCopyContextsFrom ( const TEncSbac* pSrc );
118 
119  Void codeDFFlag( UInt /*uiCode*/, const Char* /*pSymbolName*/ ) {printf("Not supported in codeDFFlag()\n"); assert(0); exit(1);};
120  Void codeDFSvlc( Int /*iCode*/, const Char* /*pSymbolName*/ ) {printf("Not supported in codeDFSvlc()\n"); assert(0); exit(1);};
121 
122 protected:
126 
127  //--Adaptive loop filter
128 
129 public:
130  Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
131  Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx );
132  Void codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx );
133  Void codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx );
134  Void codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
135  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
136 
137  Void codePartSize ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
138  Void codePredMode ( TComDataCU* pcCU, UInt uiAbsPartIdx );
139  Void codeIPCMInfo ( TComDataCU* pcCU, UInt uiAbsPartIdx );
140  Void codeTransformSubdivFlag ( UInt uiSymbol, UInt uiCtx );
141  Void codeQtCbf ( TComTU & rTu, const ComponentID compID, const Bool lowestLevel );
142  Void codeQtRootCbf ( TComDataCU* pcCU, UInt uiAbsPartIdx );
143  Void codeQtCbfZero ( TComTU &rTu, const ChannelType chType );
145  Void codeIntraDirLumaAng ( TComDataCU* pcCU, UInt absPartIdx, Bool isMultiple);
146 
147  Void codeIntraDirChroma ( TComDataCU* pcCU, UInt uiAbsPartIdx );
148  Void codeInterDir ( TComDataCU* pcCU, UInt uiAbsPartIdx );
149  Void codeRefFrmIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
150  Void codeMvd ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
151 
153 
154  Void codeDeltaQP ( TComDataCU* pcCU, UInt uiAbsPartIdx );
155  Void codeChromaQpAdjustment ( TComDataCU* cu, UInt absPartIdx );
156 
157  Void codeLastSignificantXY ( UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx );
158  Void codeCoeffNxN ( TComTU &rTu, TCoeff* pcCoef, const ComponentID compID );
159  Void codeTransformSkipFlags ( TComTU &rTu, ComponentID component );
160 
161  // -------------------------------------------------------------------------------------------------------------------
162  // for RD-optimizatioon
163  // -------------------------------------------------------------------------------------------------------------------
164 
165  Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType);
166  Void estCBFBit ( estBitsSbacStruct* pcEstBitsSbac );
168  Void estSignificantMapBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType );
169  Void estLastSignificantPositionBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, ChannelType chType );
171 
172  Void codeExplicitRdpcmMode ( TComTU &rTu, const ComponentID compID );
173 
174 
176 private:
194 
201 
203 
211 
214 
216 };
217 
219 
220 #endif // !defined(AFX_TENCSBAC_H__DDA7CDC4_EDE3_4015_9D32_2156249C82AA__INCLUDED_)
ContextModel3DBuffer m_cSaoTypeIdxSCModel
Definition: TEncSbac.h:205
Void codeQtCbfZero(TComTU &rTu, const ChannelType chType)
Definition: TEncSbac.cpp:1087
entropy encoder class (header)
Void init(TEncBinIf *p)
Definition: TEncSbac.h:72
ContextModel3DBuffer m_explicitRdpcmFlagSCModel
Definition: TEncSbac.h:208
Void estSignificantMapBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)
estimate SAMBAC bit cost for significant coefficient map
Definition: TEncSbac.cpp:1792
Void codeSplitFlag(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncSbac.cpp:613
Void codeSPS(const TComSPS *pcSPS)
Definition: TEncSbac.cpp:230
SliceType
supported slice type
Definition: TypeDef.h:343
Void resetEntropy()
Definition: TEncSbac.cpp:106
ContextModel3DBuffer m_cCUMergeFlagExtSCModel
Definition: TEncSbac.h:181
CU data structure class.
Definition: TComDataCU.h:64
ChannelType
Definition: TypeDef.h:361
Void codeCoeffNxN(TComTU &rTu, TCoeff *pcCoef, const ComponentID compID)
Definition: TEncSbac.cpp:1181
virtual Void resetBits()=0
Void estSignificantCoefficientsBit(estBitsSbacStruct *pcEstBitsSbac, ChannelType chType)
estimate bit cost of significant coefficient
Definition: TEncSbac.cpp:1935
ContextModel3DBuffer m_cCUPredModeSCModel
Definition: TEncSbac.h:184
ContextModel3DBuffer m_cCURefPicSCModel
Definition: TEncSbac.h:189
Void estCBFBit(estBitsSbacStruct *pcEstBitsSbac)
estimate bit cost for each CBP bit
Definition: TEncSbac.cpp:1746
void Void
Definition: TypeDef.h:285
Void codeSliceHeader(TComSlice *pcSlice)
Definition: TEncSbac.cpp:242
pure virtual class for basic bit handling
Definition: TComBitStream.h:58
Void estSignificantCoeffGroupMapBit(estBitsSbacStruct *pcEstBitsSbac, ChannelType chType)
estimate SAMBAC bit cost for significant coefficient group map
Definition: TEncSbac.cpp:1772
SliceType determineCabacInitIdx()
Definition: TEncSbac.cpp:163
Void codeSaoTypeIdx(UInt uiCode)
Definition: TEncSbac.cpp:1589
char Char
Definition: TypeDef.h:291
unsigned int UInt
Definition: TypeDef.h:297
TEncBinIf * m_pcBinIf
Definition: TEncSbac.h:125
ContextModel3DBuffer m_cCUInterDirSCModel
Definition: TEncSbac.h:188
Void codeSkipFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:543
Void codeSAOSign(UInt uiCode)
Definition: TEncSbac.cpp:1540
ContextModel3DBuffer m_cCUChromaPredSCModel
Definition: TEncSbac.h:186
Void codeSaoMaxUvlc(UInt code, UInt maxSymbol)
Definition: TEncSbac.cpp:1545
ContextModel3DBuffer m_cCuCtxLastX
Definition: TEncSbac.h:197
Void codeLastSignificantXY(UInt uiPosX, UInt uiPosY, Int width, Int height, ComponentID component, UInt uiScanIdx)
Definition: TEncSbac.cpp:1115
Void codeVPS(const TComVPS *pcVPS)
Definition: TEncSbac.cpp:224
ContextModel3DBuffer m_cCUDeltaQpSCModel
Definition: TEncSbac.h:187
Void codeDFFlag(UInt, const Char *)
Definition: TEncSbac.h:119
Void codePPS(const TComPPS *pcPPS)
Definition: TEncSbac.cpp:236
Void codeCrossComponentPrediction(TComTU &rTu, ComponentID compID)
Definition: TEncSbac.cpp:833
virtual ~TEncSbac()
Definition: TEncSbac.cpp:98
ContextModel3DBuffer m_cCUAbsSCModel
Definition: TEncSbac.h:200
ContextModel3DBuffer m_cCUOneSCModel
Definition: TEncSbac.h:199
Void loadContexts(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1969
Void codeIntraDirChroma(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:698
ContextModel3DBuffer m_cCUQtCbfSCModel
Definition: TEncSbac.h:191
context model class
Definition: ContextModel.h:57
ContextModel3DBuffer m_cCUSigSCModel
Definition: TEncSbac.h:196
ContextModel3DBuffer m_cCUSkipFlagSCModel
Definition: TEncSbac.h:180
ContextModel3DBuffer m_cCUTransSubdivFlagSCModel
Definition: TEncSbac.h:192
TComBitIf * m_pcBitIf
Definition: TEncSbac.h:120
Void codeIPCMInfo(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:1034
Void codeMergeFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:563
Void setSlice(TComSlice *p)
Definition: TEncSbac.h:79
bool Bool
Definition: TypeDef.h:286
ContextModel3DBuffer m_cCUPartSizeSCModel
Definition: TEncSbac.h:183
Void setBitstream(TComBitIf *p)
Definition: TEncSbac.h:78
Void xCopyContextsFrom(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:1963
Void xCopyFrom(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:422
Void xWriteUnarySymbol(UInt uiSymbol, ContextModel *pcSCModel, Int iOffset)
Definition: TEncSbac.cpp:264
ContextModel3DBuffer m_cCUQtRootCbfSCModel
Definition: TEncSbac.h:193
Int m_numContextModels
Definition: TEncSbac.h:178
virtual Void init(TComBitIf *pcTComBitIf)=0
PPS class.
Definition: TComSlice.h:977
Void codeQtCbf(TComTU &rTu, const ComponentID compID, const Bool lowestLevel)
Definition: TEncSbac.cpp:920
Void codeExplicitRdpcmMode(TComTU &rTu, const ComponentID compID)
Definition: TEncSbac.cpp:1978
Void load(const TEncSbac *pSrc)
Definition: TEncSbac.cpp:397
binary entropy encoder of CABAC
Void loadIntraDirMode(const TEncSbac *pScr, const ChannelType chType)
Definition: TEncSbac.cpp:402
Defines constants and tables for SBAC.
Void codeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)
Definition: TEncSbac.cpp:630
Void codeQtRootCbfZero(TComDataCU *pcCU)
Definition: TEncSbac.cpp:1097
ContextModel3DBuffer m_ChromaQpAdjFlagSCModel
Definition: TEncSbac.h:212
Int TCoeff
transform coefficient
Definition: TypeDef.h:693
RefPicList
reference list index
Definition: TypeDef.h:415
Void xWriteEpExGolomb(UInt uiSymbol, UInt uiCount)
Definition: TEncSbac.cpp:309
Void codeTransformSkipFlags(TComTU &rTu, ComponentID component)
Definition: TEncSbac.cpp:997
ContextModel3DBuffer m_cMVPIdxSCModel
Definition: TEncSbac.h:202
Void codeSaoMerge(UInt uiCode)
Definition: TEncSbac.cpp:1582
class for handling bitstream (header)
Void codeDFSvlc(Int, const Char *)
Definition: TEncSbac.h:120
Void codeMvd(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:779
Void codeTilesWPPEntryPoint(TComSlice *pSlice)
Definition: TEncSbac.cpp:248
UInt getNumberOfWrittenBits()
Definition: TEncSbac.h:86
Void codeDeltaQP(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:879
entropy encoder pure class
Definition: TEncEntropy.h:59
ContextModel3DBuffer m_cCrossComponentPredictionSCModel
Definition: TEncSbac.h:210
Void codePartSize(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
Definition: TEncSbac.cpp:436
ContextModel3DBuffer m_cCUIntraPredSCModel
Definition: TEncSbac.h:185
Void codeCUTransquantBypassFlag(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:532
ContextModel3DBuffer m_cTransformSkipSCModel
Definition: TEncSbac.h:206
Void estBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)
estimate bit cost for CBP, significant map and significant coefficients
Definition: TEncSbac.cpp:1722
Void codeSAOOffsetParam(ComponentID compIdx, SAOOffset &ctbParam, Bool sliceEnabled)
Definition: TEncSbac.cpp:1602
Void codePredMode(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:526
context model 3D buffer class
ContextModel m_contextModels[512]
Definition: TEncSbac.h:177
context model class (header)
binary entropy encoder interface
ContextModel3DBuffer m_cCUSplitFlagSCModel
Definition: TEncSbac.h:179
ContextModel3DBuffer m_ChromaQpAdjIdcSCModel
Definition: TEncSbac.h:213
ContextModel3DBuffer m_cCUSigCoeffGroupSCModel
Definition: TEncSbac.h:195
TEncBinIf * getEncBinIf()
Definition: TEncSbac.h:175
Definition: TComTU.h:48
Void codeTerminatingBit(UInt uilsLast)
Definition: TEncSbac.cpp:254
TComSlice * m_pcSlice
Definition: TEncSbac.h:124
Void codeSAOBlkParam(SAOBlkParam &saoBlkParam, Bool *sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo=false)
Definition: TEncSbac.cpp:1679
Void codeMergeIndex(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:583
Void resetBits()
Definition: TEncSbac.h:85
Void store(TEncSbac *pDest) const
Definition: TEncSbac.cpp:416
Void codeSliceFinish()
Definition: TEncSbac.cpp:259
Void codeMVPIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:428
ContextModel3DBuffer m_cSaoMergeSCModel
Definition: TEncSbac.h:204
UInt m_golombRiceAdaptationStatistics[4]
Definition: TEncSbac.h:215
ContextModel3DBuffer m_explicitRdpcmDirSCModel
Definition: TEncSbac.h:209
#define MAX_NUM_CTX_MOD
maximum number of supported contexts
Definition: ContextTables.h:49
int Int
Definition: TypeDef.h:296
context model 3D buffer class (header)
ContextModel3DBuffer m_cCUMvdSCModel
Definition: TEncSbac.h:190
encoder class
Definition: TEncTop.h:68
Void codeChromaQpAdjustment(TComDataCU *cu, UInt absPartIdx)
Definition: TEncSbac.cpp:906
ComponentID
Definition: TypeDef.h:368
Void estLastSignificantPositionBit(estBitsSbacStruct *pcEstBitsSbac, Int width, Int height, ChannelType chType)
estimate bit cost of significant coefficient
Definition: TEncSbac.cpp:1866
TEncSbac()
Definition: TEncSbac.cpp:57
Void codeSaoUflc(UInt uiLength, UInt uiCode)
Definition: TEncSbac.cpp:1575
Void codeRefFrmIdx(TComDataCU *pcCU, UInt uiAbsPartIdx, RefPicList eRefList)
Definition: TEncSbac.cpp:748
SBAC encoder class.
Definition: TEncSbac.h:66
Void codeInterDir(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:729
slice header class
Definition: TComSlice.h:1198
Void codeIntraDirLumaAng(TComDataCU *pcCU, UInt absPartIdx, Bool isMultiple)
Definition: TEncSbac.cpp:643
#define RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS
Definition: TypeDef.h:247
ContextModel3DBuffer m_cCuCtxLastY
Definition: TEncSbac.h:198
Void xWriteUnaryMaxSymbol(UInt uiSymbol, ContextModel *pcSCModel, Int iOffset, UInt uiMaxSymbol)
Definition: TEncSbac.cpp:281
ContextModel3DBuffer m_cCUMergeIdxExtSCModel
Definition: TEncSbac.h:182
Void xWriteCoefRemainExGolomb(UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType)
Definition: TEncSbac.cpp:338
Void uninit()
Definition: TEncSbac.h:73
ContextModel3DBuffer m_CUTransquantBypassFlagSCModel
Definition: TEncSbac.h:207
virtual UInt getNumWrittenBits()=0
SPS class.
Definition: TComSlice.h:722
virtual Void resetBits()=0
Void codeQtRootCbf(TComDataCU *pcCU, UInt uiAbsPartIdx)
Definition: TEncSbac.cpp:1071