1 /*!
2  * \copy
3  *     Copyright (c)  2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 // wels_func_ptr_def.h
34 #ifndef WELS_ENCODER_FUNCTION_POINTERS_DEFINITION_H_
35 #define WELS_ENCODER_FUNCTION_POINTERS_DEFINITION_H_
36 
37 #include "typedefs.h"
38 #include "wels_common_basis.h"
39 #include "svc_enc_macroblock.h"
40 #include "mb_cache.h"
41 #include "slice.h"
42 #include "svc_enc_slice_segment.h"
43 #include "svc_enc_frame.h"
44 #include "expand_pic.h"
45 #include "rc.h"
46 #include "IWelsVP.h"
47 #include "mc.h"
48 
49 namespace WelsEnc {
50 
51 typedef struct TagWelsEncCtx sWelsEncCtx;
52 typedef struct TagWelsFuncPointerList SWelsFuncPtrList;
53 typedef struct TagVAAFrameInfo SVAAFrameInfo;
54 
55 typedef struct TagWelsME SWelsME;
56 typedef struct TagWelsMD SWelsMD;
57 
58 typedef void (*PSetMemoryZero) (void* pDst, int32_t iSize);
59 typedef void (*PDctFunc) (int16_t* pDct, uint8_t* pSample1, int32_t iStride1, uint8_t* pSample2, int32_t iStride2);
60 
61 typedef void (*PCopyFunc) (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
62 typedef void (*PIDctFunc) (uint8_t* pRec, int32_t iStride, uint8_t* pPred, int32_t iPredStride, int16_t* pRes);
63 typedef void (*PDeQuantizationFunc) (int16_t* pRes, const uint16_t* kpQpTable);
64 typedef void (*PDeQuantizationHadamardFunc) (int16_t* pRes, const uint16_t kuiMF);
65 typedef int32_t (*PGetNoneZeroCountFunc) (int16_t* pLevel);
66 
67 typedef void (*PScanFunc) (int16_t* pLevel, int16_t* pDct);
68 typedef int32_t (*PCalculateSingleCtrFunc) (int16_t* pDct);
69 
70 typedef void (*PTransformHadamard4x4Func) (int16_t* pLumaDc, int16_t* pDct);
71 typedef void (*PQuantizationFunc) (int16_t* pDct, const int16_t* pFF, const int16_t* pMF);
72 typedef void (*PQuantizationMaxFunc) (int16_t* pDct, const int16_t* pFF, const int16_t* pMF, int16_t* pMax);
73 typedef void (*PQuantizationDcFunc) (int16_t* pDct, int16_t iFF,  int16_t iMF);
74 typedef int32_t (*PQuantizationSkipFunc) (int16_t* pDct, int16_t iFF,  int16_t iMF);
75 typedef int32_t (*PQuantizationHadamardFunc) (int16_t* pRes, const int16_t kiFF, int16_t iMF, int16_t* pDct,
76     int16_t* pBlock);
77 
78 typedef void (*PLumaDeblockingLT4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta, int8_t* iTc);
79 typedef void (*PLumaDeblockingEQ4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
80 typedef void (*PChromaDeblockingLT4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
81     int32_t iBeta, int8_t* iTc);
82 typedef void (*PChromaDeblockingEQ4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
83     int32_t iBeta);
84 typedef void (*PDeblockingBSCalc) (SWelsFuncPtrList* pFunc, SMB* pCurMb, uint8_t uiBS[2][4][4], Mb_Type uiCurMbType,
85                                    int32_t iMbStride, int32_t iLeftFlag, int32_t iTopFlag);
86 typedef void (*PDeblockingFilterSlice) (SDqLayer* pCurDq, SWelsFuncPtrList* pFunc, SSlice* pSlice);
87 
88 typedef struct tagDeblockingFunc {
89   PLumaDeblockingLT4Func    pfLumaDeblockingLT4Ver;
90   PLumaDeblockingEQ4Func    pfLumaDeblockingEQ4Ver;
91   PLumaDeblockingLT4Func    pfLumaDeblockingLT4Hor;
92   PLumaDeblockingEQ4Func    pfLumaDeblockingEQ4Hor;
93 
94   PChromaDeblockingLT4Func  pfChromaDeblockingLT4Ver;
95   PChromaDeblockingEQ4Func  pfChromaDeblockingEQ4Ver;
96   PChromaDeblockingLT4Func  pfChromaDeblockingLT4Hor;
97   PChromaDeblockingEQ4Func  pfChromaDeblockingEQ4Hor;
98 
99   PDeblockingBSCalc         pfDeblockingBSCalc;
100 
101   PDeblockingFilterSlice    pfDeblockingFilterSlice;
102 } DeblockingFunc;
103 
104 typedef  void (*PSetNoneZeroCountZeroFunc) (int8_t* pNonZeroCount);
105 
106 typedef int32_t (*PIntraFineMdFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SMB* pCurMb, SMbCache* pMbCache);
107 typedef void (*PInterFineMdFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* slice, SMB* pCurMb, int32_t bestCost);
108 typedef bool (*PInterMdFirstIntraModeFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SMB* pCurMb, SMbCache* pMbCache);
109 
110 typedef void (*PFillInterNeighborCacheFunc) (SMbCache* pMbCache, SMB* pCurMb, int32_t iMbWidth, int8_t* pVaaBgMbFlag);
111 typedef void (*PAccumulateSadFunc) (uint32_t* pSumDiff, int32_t* pGomForegroundBlockNum, int32_t* iSad8x8,
112                                     int8_t* pVaaBgMbFlag);//for RC
113 typedef bool (*PDynamicSlicingStepBackFunc) (sWelsEncCtx* pEncCtx, SSlice* pSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
114     SDynamicSlicingStack* pDynamicSlicingStack); // 2010.8.17
115 
116 typedef bool (*PInterMdBackgroundDecisionFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* slice, SMB* pCurMb,
117     SMbCache* pMbCache, bool* pKeepPskip);
118 typedef void (*PMdBackgroundInfoUpdateFunc) (SDqLayer* pCurLayer,  SMB* pCurMb, const bool bFlag,
119     const int32_t kiRefPictureType);
120 
121 typedef bool (*PInterMdScrollingPSkipDecisionFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* slice, SMB* pCurMb,
122     SMbCache* pMbCache);
123 typedef void (*PSetScrollingMv) (SVAAFrameInfo* pVaa, SWelsMD* pMd);
124 
125 typedef void (*PInterMdFunc) (sWelsEncCtx* pEncCtx, SWelsMD* pWelsMd, SSlice* slice, SMB* pCurMb, SMbCache* pMbCache);
126 
127 typedef int32_t (*PSampleSadSatdCostFunc) (uint8_t*, int32_t, uint8_t*, int32_t);
128 typedef void (*PSample4SadCostFunc) (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*);
129 typedef int32_t (*PIntraPred4x4Combined3Func) (uint8_t*, int32_t, uint8_t*, int32_t, uint8_t*, int32_t*, int32_t,
130     int32_t, int32_t);
131 typedef int32_t (*PIntraPred16x16Combined3Func) (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*);
132 typedef int32_t (*PIntraPred8x8Combined3Func) (uint8_t*, int32_t, uint8_t*, int32_t, int32_t*, int32_t, uint8_t*,
133     uint8_t*, uint8_t*);
134 
135 typedef uint32_t (*PSampleSadHor8Func) (uint8_t*, int32_t, uint8_t*, int32_t, uint16_t*, int32_t*);
136 typedef void (*PMotionSearchFunc) (SWelsFuncPtrList* pFuncList, SDqLayer* pCurDqLayer, SWelsME* pMe,
137                                    SSlice* pSlice);
138 typedef void (*PSearchMethodFunc) (SWelsFuncPtrList* pFuncList, SWelsME* pMe, SSlice* pSlice, const int32_t kiEncStride,
139                                    const int32_t kiRefStride);
140 typedef void (*PCalculateSatdFunc) (PSampleSadSatdCostFunc pSatd, SWelsME* pMe, const int32_t kiEncStride,
141                                     const int32_t kiRefStride);
142 typedef bool (*PCheckDirectionalMv) (PSampleSadSatdCostFunc pSad, SWelsME* pMe,
143                                      const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
144                                      int32_t& iBestSadCost);
145 typedef void (*PLineFullSearchFunc) (SWelsFuncPtrList* pFuncList, SWelsME* pMe,
146                                      uint16_t* pMvdTable,
147                                      const int32_t kiEncStride, const int32_t kiRefStride,
148                                      const int16_t kiMinMv, const int16_t kiMaxMv,
149                                      const bool bVerticalSearch);
150 typedef void (*PInitializeHashforFeatureFunc) (uint32_t* pTimesOfFeatureValue, uint16_t* pBuf, const int32_t kiListSize,
151     uint16_t** pLocationOfFeature, uint16_t** pFeatureValuePointerList);
152 typedef void (*PFillQpelLocationByFeatureValueFunc) (uint16_t* pFeatureOfBlock, const int32_t kiWidth,
153     const int32_t kiHeight,
154     uint16_t** pFeatureValuePointerList);
155 typedef void (*PCalculateBlockFeatureOfFrame) (uint8_t* pRef, const int32_t kiWidth, const int32_t kiHeight,
156     const int32_t kiRefStride,
157     uint16_t* pFeatureOfBlock, uint32_t pTimesOfFeatureValue[]);
158 typedef int32_t (*PCalculateSingleBlockFeature) (uint8_t* pRef, const int32_t kiRefStride);
159 typedef void (*PUpdateFMESwitch) (SDqLayer* pCurLayer);
160 
161 #define     MAX_BLOCK_TYPE BLOCK_SIZE_ALL
162 typedef struct TagSampleDealingFunc {
163   PSampleSadSatdCostFunc            pfSampleSad[MAX_BLOCK_TYPE];
164   PSampleSadSatdCostFunc            pfSampleSatd[MAX_BLOCK_TYPE];
165   PSample4SadCostFunc                 pfSample4Sad[MAX_BLOCK_TYPE];
166   PIntraPred4x4Combined3Func      pfIntra4x4Combined3Satd;
167   PIntraPred16x16Combined3Func  pfIntra16x16Combined3Satd;
168   PIntraPred16x16Combined3Func  pfIntra16x16Combined3Sad;
169   PIntraPred8x8Combined3Func      pfIntra8x8Combined3Satd;
170   PIntraPred8x8Combined3Func      pfIntra8x8Combined3Sad;
171 
172   PSampleSadSatdCostFunc*            pfMdCost;
173   PSampleSadSatdCostFunc*            pfMeCost;
174   PIntraPred16x16Combined3Func   pfIntra16x16Combined3;
175   PIntraPred8x8Combined3Func       pfIntra8x8Combined3;
176   PIntraPred4x4Combined3Func       pfIntra4x4Combined3;
177 } SSampleDealingFunc;
178 typedef void (*PGetIntraPredFunc) (uint8_t* pPrediction, uint8_t* pRef, const int32_t kiStride);
179 
180 typedef int32_t (*PGetVarianceFromIntraVaaFunc) (uint8_t* pSampelY, const int32_t kiStride);
181 typedef uint8_t (*PGetMbSignFromInterVaaFunc) (int32_t* pSad8x8);
182 typedef void (*PUpdateMbMvFunc) (SMVUnitXY* pMvUnit, const SMVUnitXY ksMv);
183 
184 typedef bool (*PBuildRefListFunc) (sWelsEncCtx* pCtx, const int32_t iPOC, int32_t iBestLtrRefIdx);
185 typedef void (*PMarkPicFunc) (sWelsEncCtx* pCtx);
186 typedef bool (*PUpdateRefListFunc) (sWelsEncCtx* pCtx);
187 typedef void (*PEndofUpdateRefListFunc) (sWelsEncCtx* pCtx);
188 typedef void (*PAfterBuildRefListFunc) (sWelsEncCtx* pCtx);
189 
190 typedef  int32_t (*PCavlcParamCalFunc) (int16_t* pCoff, uint8_t* pRun, int16_t* pLevel, int32_t* pTotalCoeffs,
191                                         int32_t iEndIdx);
192 typedef int32_t (*PWelsSpatialWriteMbSyn) (sWelsEncCtx* pCtx, SSlice* pSlice, SMB* pCurMb);
193 typedef void (*PStashMBStatus) (SDynamicSlicingStack* pDss, SSlice* pSlice, int32_t iMbSkipRun);
194 typedef int32_t (*PStashPopMBStatus) (SDynamicSlicingStack* pDss, SSlice* pSlice);
195 typedef int32_t (*PGetBsPosition)(SSlice *pSlice);
196 class IWelsParametersetStrategy;
197 
198 struct TagWelsFuncPointerList {
199   SExpandPicFunc sExpandPicFunc;
200   PFillInterNeighborCacheFunc       pfFillInterNeighborCache;
201 
202   PGetVarianceFromIntraVaaFunc  pfGetVarianceFromIntraVaa;
203   PGetMbSignFromInterVaaFunc  pfGetMbSignFromInterVaa;
204   PUpdateMbMvFunc              pfUpdateMbMv;
205   PInterMdFirstIntraModeFunc      pfFirstIntraMode; //svc_encode_slice.c svc_mode_decision.c svc_base_layer_md.c
206   PIntraFineMdFunc
207   pfIntraFineMd;          //svc_encode_slice.c svc_mode_decision.c svc_base_layer_md.c
208   PInterFineMdFunc                     pfInterFineMd;          //svc_encode_slice.c svc_base_layer_md.c
209   PInterMdFunc                           pfInterMd;
210 
211   PInterMdBackgroundDecisionFunc          pfInterMdBackgroundDecision;
212   PMdBackgroundInfoUpdateFunc      pfMdBackgroundInfoUpdate;
213 
214   PInterMdScrollingPSkipDecisionFunc pfSCDPSkipDecision;
215   PSetScrollingMv pfSetScrollingMv;
216 
217   SMcFunc                sMcFuncs;
218   SSampleDealingFunc     sSampleDealingFuncs;
219   PGetIntraPredFunc     pfGetLumaI16x16Pred[I16_PRED_DC_A];
220   PGetIntraPredFunc     pfGetLumaI4x4Pred[I4_PRED_A];
221   PGetIntraPredFunc     pfGetChromaPred[C_PRED_A];
222 
223   PSampleSadHor8Func    pfSampleSadHor8[2];     // 1: for 16x16 square; 0: for 8x8 square
224   PMotionSearchFunc
225   pfMotionSearch[BLOCK_STATIC_IDC_ALL]; //svc_encode_slice.c svc_mode_decision.c svc_enhance_layer_md.c svc_base_layer_md.c
226   PSearchMethodFunc pfSearchMethod[BLOCK_SIZE_ALL];
227   PCalculateSatdFunc pfCalculateSatd;
228   PCheckDirectionalMv pfCheckDirectionalMv;
229 
230   PInitializeHashforFeatureFunc         pfInitializeHashforFeature;
231   PFillQpelLocationByFeatureValueFunc   pfFillQpelLocationByFeatureValue;
232   PCalculateBlockFeatureOfFrame pfCalculateBlockFeatureOfFrame[2];//0 - for 8x8, 1 for 16x16
233   PCalculateSingleBlockFeature pfCalculateSingleBlockFeature[2];//0 - for 8x8, 1 for 16x16
234   PLineFullSearchFunc pfVerticalFullSearch;
235   PLineFullSearchFunc pfHorizontalFullSearch;
236   PUpdateFMESwitch pfUpdateFMESwitch;
237 
238   PCopyFunc      pfCopy16x16Aligned;    //svc_encode_slice.c svc_mode_decision.c svc_base_layer_md.c
239   PCopyFunc      pfCopy16x16NotAligned;  //md.c
240   PCopyFunc      pfCopy8x8Aligned;    //svc_encode_slice.c svc_mode_decision.c svc_base_layer_md.c md.c
241   PCopyFunc    pfCopy16x8NotAligned;  //for MeRefineFracPixel 16x8 based
242   PCopyFunc    pfCopy8x16Aligned;    //for MeRefineFracPixel 8x16 based
243   PCopyFunc      pfCopy4x4;    //not sure if aligned or not, need further tune
244   PCopyFunc      pfCopy8x4;    //not sure if aligned or not, need further tune
245   PCopyFunc      pfCopy4x8;    //not sure if aligned or not, need further tune
246 
247   PDctFunc          pfDctT4;
248   PDctFunc                pfDctFourT4;
249 
250   PCalculateSingleCtrFunc        pfCalculateSingleCtr4x4;
251   PScanFunc        pfScan4x4;    //DC/AC
252   PScanFunc        pfScan4x4Ac;
253 
254   PQuantizationFunc                pfQuantization4x4;
255   PQuantizationFunc                pfQuantizationFour4x4;
256   PQuantizationDcFunc              pfQuantizationDc4x4;
257   PQuantizationMaxFunc            pfQuantizationFour4x4Max;
258   PQuantizationHadamardFunc    pfQuantizationHadamard2x2;
259   PQuantizationSkipFunc            pfQuantizationHadamard2x2Skip;
260 
261   PTransformHadamard4x4Func   pfTransformHadamard4x4Dc;
262 
263   PGetNoneZeroCountFunc          pfGetNoneZeroCount;
264 
265   PDeQuantizationFunc              pfDequantization4x4;
266   PDeQuantizationFunc                pfDequantizationFour4x4;
267   PDeQuantizationHadamardFunc    pfDequantizationIHadamard4x4;
268   PIDctFunc                              pfIDctFourT4;
269   PIDctFunc                              pfIDctT4;
270   PIDctFunc                              pfIDctI16x16Dc;
271 
272 
273 
274   // OPTI: if MT under diff uiSliceMode, need change here
275   //PDynamicSlicingStepBackFunc  dynslc_funcpointer_stepback;//svc_encode_slice.c
276   //DYNSLC_LNGTH_CRTL    dynslc_funcpointer_slcsize_ctrl;
277 
278   /* For Deblocking */
279   DeblockingFunc                         pfDeblocking;
280   PSetNoneZeroCountZeroFunc     pfSetNZCZero;
281 
282   SWelsRcFunc              pfRc;
283   PAccumulateSadFunc         pfAccumulateSadForRc;
284 
285   PSetMemoryZero        pfSetMemZeroSize8;      // for size is times to 8
286   PSetMemoryZero        pfSetMemZeroSize64Aligned16;      // for size is times of 64, and address is align to 16
287   PSetMemoryZero        pfSetMemZeroSize64;      // for size is times of 64, and don't know address is align to 16 or not
288 
289   PCavlcParamCalFunc    pfCavlcParamCal;
290   PWelsSpatialWriteMbSyn pfWelsSpatialWriteMbSyn;
291   PGetBsPosition pfGetBsPosition;
292   PStashMBStatus pfStashMBStatus;
293   PStashPopMBStatus pfStashPopMBStatus;
294 
295   IWelsParametersetStrategy* pParametersetStrategy;
296 };
297 
298 }  //end of namespace WelsEnc {
299 
300 #endif//WELS_ENCODER_FUNCTION_POINTERS_DEFINITION_H_
301