source: 3DVCSoftware/branches/0.3-nokia/source/Lib/TLibEncoder/TEncSbac.h @ 193

Last change on this file since 193 was 50, checked in by nokia, 13 years ago

FCO bug-fix to 3DV-HTM version 0.4: decoder crushed with texture-only coding.

  • Property svn:eol-style set to native
File size: 11.5 KB
Line 
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     TEncSbac.h
37    \brief    Context-adaptive entropy encoder class (header)
38*/
39
40#ifndef __TENCSBAC__
41#define __TENCSBAC__
42
43#if _MSC_VER > 1000
44#pragma once
45#endif // _MSC_VER > 1000
46
47#include "../TLibCommon/TComBitStream.h"
48#include "../TLibCommon/ContextTables.h"
49#include "../TLibCommon/ContextModel.h"
50#include "../TLibCommon/ContextModel3DBuffer.h"
51#include "TEncEntropy.h"
52#include "TEncBinCoder.h"
53#include "TEncBinCoderCABAC.h"
54
55class TEncTop;
56
57// ====================================================================================================================
58// Class definition
59// ====================================================================================================================
60
61/// SBAC encoder class
62class TEncSbac : public TEncEntropyIf
63{
64public:
65  TEncSbac();
66  virtual ~TEncSbac();
67 
68  Void  init                   ( TEncBinIf* p )  { m_pcBinIf = p; }
69  Void  uninit                 ()                { m_pcBinIf = 0; }
70 
71  //  Virtual list
72  Void  resetEntropy           ();
73  Void  setBitstream           ( TComBitIf* p )  { m_pcBitIf = p; m_pcBinIf->init( p ); }
74  Void  setSlice               ( TComSlice* p )  { m_pcSlice = p;                       }
75 
76  Bool  getAlfCtrl             ()                         { return m_bAlfCtrl;          }
77  UInt  getMaxAlfCtrlDepth     ()                         { return m_uiMaxAlfCtrlDepth; }
78  Void  setAlfCtrl             ( Bool bAlfCtrl          ) { m_bAlfCtrl          = bAlfCtrl;          }
79  Void  setMaxAlfCtrlDepth     ( UInt uiMaxAlfCtrlDepth ) { m_uiMaxAlfCtrlDepth = uiMaxAlfCtrlDepth; }
80 
81  // SBAC RD
82  Void  resetCoeffCost         ()                { m_uiCoeffCost = 0;  }
83  UInt  getCoeffCost           ()                { return  m_uiCoeffCost;  }
84 
85  Void  load                   ( TEncSbac* pScr  );
86  Void  store                  ( TEncSbac* pDest );
87  Void  resetBits              ()                { m_pcBinIf->resetBits(); m_pcBitIf->resetBits(); }
88  UInt  getNumberOfWrittenBits ()                { return m_pcBinIf->getNumWrittenBits(); }
89  //--SBAC RD
90 
91#if BITSTREAM_EXTRACTION
92  Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, UInt uiLayerId = 0 );
93#else
94  Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, Bool bOutputFlag = true );
95#endif
96
97  Void  codeSPS                 ( TComSPS* pcSPS     );
98  Void  codePPS                 ( TComPPS* pcPPS     );
99  void codeSEI(const SEI&);
100  Void  codeSliceHeader         ( TComSlice* pcSlice );
101  Void  codeTerminatingBit      ( UInt uilsLast      );
102  Void  codeSliceFinish         ();
103 
104  Void  codeAlfFlag       ( UInt uiCode );
105  Void  codeAlfUvlc       ( UInt uiCode );
106  Void  codeAlfSvlc       ( Int  uiCode );
107  Void  codeAlfCtrlDepth  ();
108#if TSB_ALF_HEADER
109  Void codeAlfFlagNum        ( UInt uiCode, UInt minValue );
110  Void codeAlfCtrlFlag       ( UInt uiSymbol );
111#endif
112#if MTK_SAO
113  Void  codeAoFlag       ( UInt uiCode );
114  Void  codeAoUvlc       ( UInt uiCode );
115  Void  codeAoSvlc       ( Int  uiCode );
116#endif
117
118private:
119  Void  xWriteUnarySymbol    ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset );
120  Void  xWriteUnaryMaxSymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol );
121  Void  xWriteEpExGolomb     ( UInt uiSymbol, UInt uiCount );
122#if E253
123  Void  xWriteGoRiceExGolomb ( UInt uiSymbol, UInt &ruiGoRiceParam );
124#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
125  Void  xWriteExGolombLevel  ( UInt uiSymbol, ContextModel& rcSCModel  );
126#endif
127#else
128  Void  xWriteExGolombLevel  ( UInt uiSymbol, ContextModel& rcSCModel  );
129#endif
130  Void  xWriteTerminatingBit ( UInt uiBit );
131 
132  Void  xCheckCoeff( TCoeff* pcCoef, UInt uiSize, UInt uiDepth, UInt& uiNumofCoeff, UInt& uiPart );
133
134#if MVD_CTX
135  Void  xWriteMvd            ( Int iMvd, UInt uiAbsSumL, UInt uiAbsSumA, UInt uiCtx );
136#else
137  Void  xWriteMvd            ( Int iMvd, UInt uiAbsSum, UInt uiCtx );
138#endif
139  Void  xWriteExGolombMvd    ( UInt uiSymbol, ContextModel* pcSCModel, UInt uiMaxBin );
140  Void  xCopyFrom            ( TEncSbac* pSrc );
141 
142#if HHI_DMM_WEDGE_INTRA
143  Void  xCodeWedgeFullInfo   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
144  Void  xCodeWedgeFullDeltaInfo     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
145
146  Void  xCodeWedgePredDirInfo       ( TComDataCU* pcCU, UInt uiAbsPartIdx );
147  Void  xCodeWedgePredDirDeltaInfo  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
148#endif
149#if HHI_DMM_PRED_TEX
150  Void  xCodeWedgePredTexDeltaInfo  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
151  Void  xCodeContourPredTexDeltaInfo( TComDataCU* pcCU, UInt uiAbsPartIdx );
152#endif
153 
154protected:
155  TComBitIf*    m_pcBitIf;
156  TComSlice*    m_pcSlice;
157  TEncBinIf*    m_pcBinIf;
158  Bool          m_bAlfCtrl;
159 
160  //SBAC RD
161  UInt          m_uiCoeffCost;
162 
163  // Adaptive loop filter
164  UInt          m_uiMaxAlfCtrlDepth;
165  //--Adaptive loop filter
166
167public:
168  Void codeAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
169  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
170  Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
171  Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
172#if HHI_INTER_VIEW_MOTION_PRED || HHI_MPI
173  Void codeMergeIndexMV  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
174#endif
175#if HHI_INTER_VIEW_RESIDUAL_PRED
176  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
177#endif
178  Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
179  Void codeMVPIdx        ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
180 
181  Void codePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth );
182  Void codePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
183 
184  Void codeTransformSubdivFlag ( UInt uiSymbol, UInt uiCtx );
185  Void codeQtCbf               ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth );
186  Void codeQtRootCbf           ( TComDataCU* pcCU, UInt uiAbsPartIdx );
187 
188  Void codeIntraDirLumaAng     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
189 
190  Void codeIntraDirChroma      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
191  Void codeInterDir            ( TComDataCU* pcCU, UInt uiAbsPartIdx );
192  Void codeRefFrmIdx           ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
193  Void codeMvd                 ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
194 
195  Void codeViewIdx                       (Int iViewIdx);
196
197  Void codeDeltaQP             ( TComDataCU* pcCU, UInt uiAbsPartIdx );
198  Void codeCbf                 ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) {}
199  Void codeBlockCbf            ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiQPartNum, Bool bRD = false ) {}
200 
201#if CAVLC_RQT_CBP
202  Void codeCbfTrdiv      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) {}
203  UInt xGetFlagPattern   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) { return 0; }
204#endif
205#if PCP_SIGMAP_SIMPLE_LAST
206  __inline Void codeLastSignificantXY ( UInt uiPosX, UInt uiPosY, const UInt uiWidth, const TextType eTType, const UInt uiCTXIdx, const UInt uiScanIdx );
207#endif
208  Void codeCoeffNxN            ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType, Bool bRD = false );
209 
210  // -------------------------------------------------------------------------------------------------------------------
211  // for RD-optimizatioon
212  // -------------------------------------------------------------------------------------------------------------------
213 
214  Void estBit                        ( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType );
215  Void estCBFBit                     ( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType );
216  Void estSignificantMapBit          ( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType );
217  Void estSignificantCoefficientsBit ( estBitsSbacStruct* pcEstBitsSbac, UInt uiCTXIdx, TextType eTType );
218 
219  __inline Int  biari_no_bits        ( Short symbol, ContextModel& rcSCModel );
220 
221  TEncBinIf* getEncBinIf()  { return m_pcBinIf; }
222private:
223  UInt                 m_uiLastQp;
224  ContextModel3DBuffer m_cCUSplitFlagSCModel;
225  ContextModel3DBuffer m_cCUSkipFlagSCModel;
226  ContextModel3DBuffer m_cCUMergeFlagExtSCModel;
227  ContextModel3DBuffer m_cCUMergeIdxExtSCModel;
228  ContextModel3DBuffer m_cCUMVMergeIdxExtSCModel;
229  ContextModel3DBuffer m_cResPredFlagSCModel;
230  ContextModel3DBuffer m_cCUPartSizeSCModel;
231  ContextModel3DBuffer m_cCUPredModeSCModel;
232  ContextModel3DBuffer m_cCUAlfCtrlFlagSCModel;
233  ContextModel3DBuffer m_cCUIntraPredSCModel;
234#if ADD_PLANAR_MODE
235  ContextModel3DBuffer m_cPlanarFlagSCModel;
236#endif
237  ContextModel3DBuffer m_cCUChromaPredSCModel;
238  ContextModel3DBuffer m_cCUDeltaQpSCModel;
239  ContextModel3DBuffer m_cCUInterDirSCModel;
240  ContextModel3DBuffer m_cCURefPicSCModel;
241  ContextModel3DBuffer m_cCUMvdSCModel;
242  ContextModel3DBuffer m_cCUQtCbfSCModel;
243  ContextModel3DBuffer m_cCUTransSubdivFlagSCModel;
244  ContextModel3DBuffer m_cCUQtRootCbfSCModel;
245 
246  ContextModel3DBuffer m_cCUSigSCModel;
247#if PCP_SIGMAP_SIMPLE_LAST
248  ContextModel3DBuffer m_cCuCtxLastX;
249  ContextModel3DBuffer m_cCuCtxLastY;
250#else
251  ContextModel3DBuffer m_cCULastSCModel;
252#endif
253  ContextModel3DBuffer m_cCUOneSCModel;
254  ContextModel3DBuffer m_cCUAbsSCModel;
255 
256  ContextModel3DBuffer m_cMVPIdxSCModel;
257 
258  ContextModel3DBuffer m_cALFFlagSCModel;
259  ContextModel3DBuffer m_cALFUvlcSCModel;
260  ContextModel3DBuffer m_cALFSvlcSCModel;
261#if MTK_SAO
262  ContextModel3DBuffer m_cAOFlagSCModel;
263  ContextModel3DBuffer m_cAOUvlcSCModel;
264  ContextModel3DBuffer m_cAOSvlcSCModel;
265#endif
266  ContextModel3DBuffer m_cViewIdxSCModel;
267#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
268  ContextModel3DBuffer m_cIntraDMMSCModel;
269  ContextModel3DBuffer m_cIntraWedgeSCModel;
270#endif
271};
272
273#endif // !defined(AFX_TENCSBAC_H__DDA7CDC4_EDE3_4015_9D32_2156249C82AA__INCLUDED_)
Note: See TracBrowser for help on using the repository browser.