source: 3DVCSoftware/branches/HTM-6.2-dev2-Qualcomm/source/Lib/TLibEncoder/TEncEntropy.h @ 1288

Last change on this file since 1288 was 373, checked in by zhang, 12 years ago

JCT3V-D0177: ARP

  • Property svn:eol-style set to native
File size: 16.9 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[56]6 * Copyright (c) 2010-2012, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TEncEntropy.h
35    \brief    entropy encoder class (header)
36*/
37
38#ifndef __TENCENTROPY__
39#define __TENCENTROPY__
40
[56]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/TComAdaptiveLoopFilter.h"
48#include "TLibCommon/TComSampleAdaptiveOffset.h"
49
[2]50class TEncSbac;
51class TEncCavlc;
52class SEI;
53
54// ====================================================================================================================
55// Class definition
56// ====================================================================================================================
57
58/// entropy encoder pure class
59class TEncEntropyIf
60{
61public:
62  virtual Bool getAlfCtrl()                = 0;
63  virtual UInt getMaxAlfCtrlDepth()                = 0;
64  virtual Void setAlfCtrl(Bool bAlfCtrl)                = 0;
65  virtual Void setMaxAlfCtrlDepth(UInt uiMaxAlfCtrlDepth)                = 0;
66 
67  virtual Void  resetEntropy          ()                = 0;
[56]68#if CABAC_INIT_FLAG
69  virtual Void  determineCabacInitIdx ()                = 0;
70#endif
[2]71  virtual Void  setBitstream          ( TComBitIf* p )  = 0;
72  virtual Void  setSlice              ( TComSlice* p )  = 0;
73  virtual Void  resetBits             ()                = 0;
74  virtual Void  resetCoeffCost        ()                = 0;
75  virtual UInt  getNumberOfWrittenBits()                = 0;
76  virtual UInt  getCoeffCost          ()                = 0;
[56]77
[210]78#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
[100]79  virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
[77]80#endif
[100]81
[332]82#if HHI_MPI || H3D_QTL
[56]83  virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
[42]84#else
[56]85  virtual Void  codeSPS                 ( TComSPS* pcSPS )                                      = 0;
[42]86#endif
[2]87  virtual Void  codePPS                 ( TComPPS* pcPPS )                                      = 0;
88  virtual void codeSEI(const SEI&) = 0;
89  virtual Void  codeSliceHeader         ( TComSlice* pcSlice )                                  = 0;
[56]90  virtual Void codeTileMarkerFlag      ( TComSlice* pcSlice )                                  = 0;
91
92  virtual Void  codeTilesWPPEntryPoint  ( TComSlice* pSlice )     = 0;
[2]93  virtual Void  codeTerminatingBit      ( UInt uilsLast )                                       = 0;
94  virtual Void  codeSliceFinish         ()                                                      = 0;
[56]95  virtual Void  codeFlush               ()                                                      = 0;
96  virtual Void  encodeStart             ()                                                      = 0;
[2]97 
98  virtual Void codeAlfCtrlDepth() = 0;
[296]99#if H3D_IVMP
[56]100  virtual Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum ) = 0;
101#else
[2]102  virtual Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) = 0;
[56]103#endif
104  virtual Void codeScalingList   ( TComScalingList* scalingList )      = 0;
[2]105 
106public:
107  virtual Void codeAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
[56]108  virtual Void codeApsExtensionFlag () = 0;
[2]109 
110  virtual Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
[189]111#if LGE_ILLUCOMP_B0045
112  virtual Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
113#endif
[2]114  virtual Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
115  virtual Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
[296]116#if H3D_IVRP
[2]117  virtual Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
[5]118#endif
[373]119#if QC_ARP_D0177
120  virtual Void codeARPW         ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
121#endif
[2]122  virtual Void codeSplitFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
123 
124  virtual Void codePartSize      ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) = 0;
125  virtual Void codePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
126 
[189]127#if RWTH_SDC_DLT_B0036
128  virtual Void codeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
129  virtual Void codeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) = 0;
130  virtual Void codeSDCPredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
131#endif
132 
[56]133  virtual Void codeIPCMInfo      ( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag) = 0;
134
[2]135  virtual Void codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) = 0;
136  virtual Void codeQtCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) = 0;
137  virtual Void codeQtRootCbf     ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
138  virtual Void codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
139 
140  virtual Void codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
141  virtual Void codeInterDir      ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
142  virtual Void codeRefFrmIdx     ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )      = 0;
143  virtual Void codeMvd           ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList )      = 0;
144  virtual Void codeDeltaQP       ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
[56]145  virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
[2]146 
147  virtual Void codeAlfFlag          ( UInt uiCode ) = 0;
148  virtual Void codeAlfUvlc          ( UInt uiCode ) = 0;
149  virtual Void codeAlfSvlc          ( Int   iCode ) = 0;
[56]150  virtual Void codeAlfFixedLengthIdx( UInt idx, UInt numFilterSetsInBuffer) = 0;
151  virtual Void codeAPSAlflag(UInt uiCode) = 0;
152  /// set slice granularity
153  virtual Void setSliceGranularity(Int iSliceGranularity) = 0;
154
155  /// get slice granularity
156  virtual Int  getSliceGranularity()                      = 0;
157
[2]158  virtual Void codeAlfCtrlFlag      ( UInt uiSymbol ) = 0;
[56]159  virtual Void codeSaoFlag          ( UInt uiCode ) = 0;
160  virtual Void codeSaoUvlc          ( UInt uiCode ) = 0;
161  virtual Void codeSaoSvlc          ( Int   iCode ) = 0;
162  virtual Void codeSaoRun          ( UInt   uiCode, UInt uiMaxValue  ) = 0;
163  virtual Void codeSaoMergeLeft    ( UInt   uiCode, UInt uiCompIdx  ) = 0;
164  virtual Void codeSaoMergeUp      ( UInt   uiCode) = 0;
165  virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
166  virtual Void codeSaoUflc         ( UInt   uiCode) = 0;
167  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
[2]168 
[56]169  virtual Void updateContextTables ( SliceType eSliceType, Int iQp, Bool bExecuteFinish )   = 0;
170  virtual Void updateContextTables ( SliceType eSliceType, Int iQp )   = 0;
171  virtual Void writeTileMarker             ( UInt uiTileIdx, UInt uiBitsUsed ) = 0;
172
173  virtual Void codeAPSInitInfo  (TComAPS* pcAPS)= 0;
174  virtual Void codeFinish       (Bool bEnd)= 0;
175
176  virtual Void codeDFFlag (UInt uiCode, const Char *pSymbolName) = 0;
177  virtual Void codeDFSvlc (Int iCode, const Char *pSymbolName)   = 0;
178
[2]179  virtual ~TEncEntropyIf() {}
[56]180
[2]181};
182
183/// entropy encoder class
184class TEncEntropy
185{
[56]186private:
187  UInt    m_uiBakAbsPartIdx;
188  UInt    m_uiBakChromaOffset;
189  UInt    m_bakAbsPartIdxCU;
190
[2]191public:
192  Void    setEntropyCoder           ( TEncEntropyIf* e, TComSlice* pcSlice );
193  Void    setBitstream              ( TComBitIf* p )          { m_pcEntropyCoderIf->setBitstream(p);  }
194  Void    resetBits                 ()                        { m_pcEntropyCoderIf->resetBits();      }
195  Void    resetCoeffCost            ()                        { m_pcEntropyCoderIf->resetCoeffCost(); }
196  UInt    getNumberOfWrittenBits    ()                        { return m_pcEntropyCoderIf->getNumberOfWrittenBits(); }
197  UInt    getCoeffCost              ()                        { return  m_pcEntropyCoderIf->getCoeffCost(); }
198  Void    resetEntropy              ()                        { m_pcEntropyCoderIf->resetEntropy();  }
[56]199#if CABAC_INIT_FLAG
200  Void    determineCabacInitIdx     ()                        { m_pcEntropyCoderIf->determineCabacInitIdx(); }
201#endif
[2]202 
203  Void    encodeSliceHeader         ( TComSlice* pcSlice );
[56]204  Void    encodeTileMarkerFlag       (TComSlice* pcSlice) {m_pcEntropyCoderIf->codeTileMarkerFlag(pcSlice);}
205  Void    encodeTilesWPPEntryPoint( TComSlice* pSlice );
[2]206  Void    encodeTerminatingBit      ( UInt uiIsLast );
207  Void    encodeSliceFinish         ();
[56]208  Void    encodeFlush               ();
209  Void    encodeStart               ();
210  Void encodeAlfFlag(UInt code) {m_pcEntropyCoderIf->codeAlfFlag(code);}
211  Void encodeAlfStoredFilterSetIdx(UInt idx, UInt numFilterSetsInBuffer);
212  Void encodeAlfFixedLengthRun(UInt run, UInt rx, UInt numLCUInWidth);
213  Void encodeAlfParam(AlfParamSet* pAlfParamSet, Bool bSentInAPS = true, Int firstLCUAddr = 0, Bool alfAcrossSlice= true);
214  Void encodeAlfParamSet(AlfParamSet* pAlfParamSet, Int numLCUInWidth, Int numLCU, Int firstLCUAddr, Bool alfAcrossSlice, Int startCompIdx, Int endCompIdx);
215  Bool getAlfRepeatRowFlag(Int compIdx, AlfParamSet* pAlfParamSet, Int lcuIdx, Int lcuPos, Int startlcuPosX, Int endlcuPosX, Int numLCUInWidth);
216  Int  getAlfRun(Int compIdx, AlfParamSet* pAlfParamSet, Int lcuIdxInSlice, Int lcuPos, Int startlcuPosX, Int endlcuPosX);
217  Void encodeAPSAlfFlag(UInt code) {m_pcEntropyCoderIf->codeAPSAlflag(code);}
[2]218  Void encodeAlfParam(ALFParam* pAlfParam);
219 
220  TEncEntropyIf*      m_pcEntropyCoderIf;
221 
222public:
[210]223#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
[100]224  Void encodeVPS               ( TComVPS* pcVPS);
[77]225#endif
[2]226  // SPS
[332]227#if HHI_MPI || H3D_QTL
[56]228  Void encodeSPS               ( TComSPS* pcSPS, Bool bIsDepth );
229#else
[2]230  Void encodeSPS               ( TComSPS* pcSPS );
[56]231#endif
[2]232  Void encodePPS               ( TComPPS* pcPPS );
233  void encodeSEI(const SEI&);
234  Bool getAlfCtrl() {return m_pcEntropyCoderIf->getAlfCtrl();}
235  UInt getMaxAlfCtrlDepth() {return m_pcEntropyCoderIf->getMaxAlfCtrlDepth();}
236  Void setAlfCtrl(Bool bAlfCtrl) {m_pcEntropyCoderIf->setAlfCtrl(bAlfCtrl);}
237  Void setMaxAlfCtrlDepth(UInt uiMaxAlfCtrlDepth) {m_pcEntropyCoderIf->setMaxAlfCtrlDepth(uiMaxAlfCtrlDepth);}
238 
239  Void encodeSplitFlag         ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
[189]240#if LGE_ILLUCOMP_B0045
[296]241  Void encodeICFlag            ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false 
242#if LGE_ILLUCOMP_DEPTH_C0046
243      , UInt uiDepth = 0
[189]244#endif
[296]245      );
246#endif
[2]247  Void encodeSkipFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
248  Void encodePUWise       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
249  Void encodeInterDirPU   ( TComDataCU* pcSubCU, UInt uiAbsPartIdx  );
250  Void encodeRefFrmIdxPU  ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList );
251  Void encodeMvdPU        ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList );
252  Void encodeMVPIdxPU     ( TComDataCU* pcSubCU, UInt uiAbsPartIdx, RefPicList eRefList );
253  Void encodeMergeFlag    ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx );
254  Void encodeMergeIndex   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPUIdx, Bool bRD = false );
[373]255#if QC_ARP_D0177
256  Void encodeARPW              ( TComDataCU* pcCU, UInt uiAbspartIdx , Bool bRD = false, UInt uiDepth = -1);
257#endif
[2]258  Void encodeAlfCtrlFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
[56]259
260  /// set slice granularity
261  Void setSliceGranularity (Int iSliceGranularity) {m_pcEntropyCoderIf->setSliceGranularity(iSliceGranularity);}
262
263  /// encode ALF CU control flag
264  Void encodeAlfCtrlFlag(UInt uiFlag);
265 
266  Void encodeApsExtensionFlag() {m_pcEntropyCoderIf->codeApsExtensionFlag();};
267
268  Void encodeAlfCtrlParam(AlfCUCtrlInfo& cAlfParam, Int iNumCUsInPic);
269
[2]270  Void encodePredMode          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
271  Void encodePartSize          ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Bool bRD = false );
[56]272  Void encodeIPCMInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
[2]273  Void encodePredInfo          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
274  Void encodeIntraDirModeLuma  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
275 
276  Void encodeIntraDirModeChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
277 
278  Void encodeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx );
279  Void encodeQtCbf             ( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth );
280  Void encodeQtRootCbf         ( TComDataCU* pcCU, UInt uiAbsPartIdx );
281  Void encodeQP                ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
[56]282  Void updateContextTables     ( SliceType eSliceType, Int iQp, Bool bExecuteFinish )   { m_pcEntropyCoderIf->updateContextTables( eSliceType, iQp, bExecuteFinish );     }
283  Void updateContextTables     ( SliceType eSliceType, Int iQp )                        { m_pcEntropyCoderIf->updateContextTables( eSliceType, iQp, true );               }
284  Void writeTileMarker              ( UInt uiTileIdx, UInt uiBitsUsed ) { m_pcEntropyCoderIf->writeTileMarker( uiTileIdx, uiBitsUsed ); }
[2]285 
[56]286  Void encodeAPSInitInfo          (TComAPS* pcAPS) {m_pcEntropyCoderIf->codeAPSInitInfo(pcAPS);}
287  Void encodeFinish               (Bool bEnd) {m_pcEntropyCoderIf->codeFinish(bEnd);}
288  Void encodeScalingList       ( TComScalingList* scalingList );
289  Void encodeDFParams          (TComAPS* pcAPS);
[189]290 
291#if RWTH_SDC_DLT_B0036
292  Void encodeSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
293  Void encodeSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
294  Void encodeSDCPredMode   ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
295#endif
[56]296
[2]297private:
[56]298  Void xEncodeTransform        ( TComDataCU* pcCU,UInt offsetLumaOffset, UInt offsetChroma, UInt uiAbsPartIdx, UInt absTUPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, UInt uiInnerQuadIdx, UInt& uiYCbfFront3, UInt& uiUCbfFront3, UInt& uiVCbfFront3, Bool& bCodeDQP );
[2]299public:
[56]300  Void encodeCoeff             ( TComDataCU* pcCU,                 UInt uiAbsPartIdx, UInt uiDepth, UInt uiWidth, UInt uiHeight, Bool& bCodeDQP );
[2]301 
[56]302  Void encodeCoeffNxN         ( TComDataCU* pcCU, TCoeff* pcCoeff, UInt uiAbsPartIdx, UInt uiTrWidth, UInt uiTrHeight, UInt uiDepth, TextType eType );
[2]303 
[56]304  Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
[2]305 
306  // ALF-related
307  Void codeAuxCountBit(ALFParam* pAlfParam, Int64* ruiRate);
308  Void codeFiltCountBit(ALFParam* pAlfParam, Int64* ruiRate);
309  Void codeAux (ALFParam* pAlfParam);
310  Void codeFilt (ALFParam* pAlfParam);
311  Int codeFilterCoeff(ALFParam* ALFp);
[56]312  Int writeFilterCodingParams(int minKStart, int minScanVal, int maxScanVal, int kMinTab[]);
313
[2]314  Int writeFilterCoeffs(int sqrFiltLength, int filters_per_group, int pDepthInt[], 
315                        int **FilterCoeff, int kMinTab[]);
316  Int golombEncode(int coeff, int k);
317  Int lengthGolomb(int coeffVal, int k);
[56]318  Void    encodeSaoUnit(Int rx, Int ry, Int compIdx, SAOParam* saoParam, Int repeatedRow);
319  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam);
320  Void    encodeSaoUnitInterleaving(Int rx, Int ry, SAOParam* saoParam, TComDataCU* cu, Int cuAddrInSlice, Int cuAddrUpInSlice, Bool lfCrossSliceBoundaryFlag);
321  Void    encodeSaoParam         (TComAPS*  aps);
[2]322
[56]323  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
324
[2]325};// END CLASS DEFINITION TEncEntropy
326
[56]327//! \}
[2]328
329#endif // __TENCENTROPY__
330
Note: See TracBrowser for help on using the repository browser.