History

Merge pull request #1772 from mstorsjo/mc-unify

Move the MC implementation to the common library

dongzha committed 11 years ago

Commit 4f4adce2 parents 59b3b42 605f2fb24 files · +490 −1409Browse files

Showing the changes to test/encoder/EncUT_MotionCompensation.cpp (1 of 24 files). Show all

Unified · Split

test/encoder/EncUT_MotionCompensation.cpp+275−24
@@ -1,36 +1,287 @@
11 #include <gtest/gtest.h>
22 #include "codec_def.h"
3+#include "macros.h"
34 #include "mc.h"
45 #include "cpu.h"
5−using namespace WelsEnc;
6+using namespace WelsCommon;
67
7−static void McLumaFunc (SMcFunc* pFuncs, const uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride,
8− int16_t iMvX, int16_t iMvY, int32_t iWidth, int32_t iHeight) {
9− uint8_t uiMvpIdx = ((iMvY & 0x03) << 2) + (iMvX & 0x03);
10− ASSERT_EQ (iWidth, 16);
11− pFuncs->pfLumaQuarpelMc[uiMvpIdx] (pSrc, iSrcStride, pDst, iDstStride, iHeight);
8+#define MC_BUFF_SRC_STRIDE 32
9+#define MC_BUFF_DST_STRIDE 32
10+#define MC_BUFF_HEIGHT 30
11+
12+/**********************MC Unit Test Anchor Code Begin******************************/
13+static bool bQpelNeeded[4][4] = {
14+ { false, true, false, true },
15+ { true, true, true, true },
16+ { false, true, false, true },
17+ { true, true, true, true }
18+};
19+static int32_t iHpelRef0Array[4][4] = {
20+ { 0, 1, 1, 1 },
21+ { 0, 1, 1, 1 },
22+ { 2, 3, 3, 3 },
23+ { 0, 1, 1, 1 }
24+};
25+static int32_t iHpelRef1Array[4][4] = {
26+ { 0, 0, 0, 0 },
27+ { 2, 2, 3, 2 },
28+ { 2, 2, 3, 2 },
29+ { 2, 2, 3, 2 }
30+};
31+#define FILTER6TAP(pPixBuff, x, iStride) ((pPixBuff)[x-2*iStride] + (pPixBuff)[x+3*iStride] - 5*((pPixBuff)[x-iStride] + (pPixBuff)[x+2*iStride]) + 20*((pPixBuff)[x] + (pPixBuff)[x+iStride]))
32+static inline uint8_t Clip255 (int32_t x) {
33+ return ((x & ~255) ? (-x) >> 31 & 255 : x);
34+}
35+
36+static void MCCopyAnchor (uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride, int32_t iWidth,
37+ int32_t iHeight) {
38+ for (int32_t y = 0; y < iHeight; y++) {
39+ memcpy (pDst, pSrc, iWidth * sizeof (uint8_t));
40+ pSrc += iSrcStride;
41+ pDst += iDstStride;
42+ }
1243 }
1344
14−#define InitMcFunc WelsInitMcFuncs
45+static void MCHalfPelFilterAnchor (uint8_t* pDstH, uint8_t* pDstV, uint8_t* pDstHV, uint8_t* pSrc,
46+ int32_t iStride, int32_t iWidth, int32_t iHeight, int16_t* pBuf) {
47+ for (int32_t y = 0; y < iHeight; y++) {
48+ for (int32_t x = 0; x < iWidth; x++)
49+ pDstH[x] = Clip255 ((FILTER6TAP (pSrc, x, 1) + 16) >> 5);
50+ for (int32_t x = -2; x < iWidth + 3; x++) {
51+ int32_t v = FILTER6TAP (pSrc, x, iStride);
52+ pDstV[x] = Clip255 ((v + 16) >> 5);
53+ pBuf[x + 2] = v;
54+ }
55+ for (int32_t x = 0; x < iWidth; x++)
56+ pDstHV[x] = Clip255 ((FILTER6TAP (pBuf + 2, x, 1) + 512) >> 10);
57+ pDstH += iStride;
58+ pDstV += iStride;
59+ pDstHV += iStride;
60+ pSrc += iStride;
61+ }
62+}
1563
16−#define LUMA_FUNC(funcs, src, srcstride, dst, dststride, mvx, mvy, width, height) \
17− McLumaFunc (funcs, src, srcstride, dst, dststride, mvx, mvy, width, height)
64+static void PixelAvgAnchor (uint8_t* pDst, int32_t iDstStride,
65+ uint8_t* pSrc1, int32_t iSrc1Stride,
66+ uint8_t* pSrc2, int32_t iSrc2Stride, int32_t iWidth, int32_t iHeight) {
67+ for (int32_t y = 0; y < iHeight; y++) {
68+ for (int32_t x = 0; x < iWidth; x++)
69+ pDst[x] = (pSrc1[x] + pSrc2[x] + 1) >> 1;
70+ pDst += iDstStride;
71+ pSrc1 += iSrc1Stride;
72+ pSrc2 += iSrc2Stride;
73+ }
74+}
1875
19−#define CHROMA_FUNC sMcFunc.pfChromaMc
76+static void MCLumaAnchor (uint8_t* pDst, int32_t iDstStride, uint8_t* pSrc[4], int32_t iSrcStride,
77+ int32_t iMvX, int32_t iMvY, int32_t iWidth, int32_t iHeight) {
78+ int32_t iMvXIdx = iMvX & 3;
79+ int32_t iMvYIdx = iMvY & 3;
80+ int32_t iOffset = (iMvY >> 2) * iSrcStride + (iMvX >> 2);
81+ uint8_t* pSrc1 = pSrc[iHpelRef0Array[iMvYIdx][iMvXIdx]] + iOffset + ((iMvYIdx) == 3) * iSrcStride;
2082
21−#include "mc_test_common.h"
83+ if (bQpelNeeded[iMvYIdx][iMvXIdx]) {
84+ uint8_t* pSrc2 = pSrc[iHpelRef1Array[iMvYIdx][iMvXIdx]] + iOffset + ((iMvXIdx) == 3);
85+ PixelAvgAnchor (pDst, iDstStride, pSrc1, iSrcStride, pSrc2, iSrcStride, iWidth, iHeight);
86+ } else {
87+ MCCopyAnchor (pSrc1, iSrcStride, pDst, iDstStride, iWidth, iHeight);
88+ }
89+}
2290
23−DEF_MCCOPYTEST (Enc, 16, 8)
24−DEF_MCCOPYTEST (Enc, 16, 16)
91+static void MCChromaAnchor (uint8_t* pDstU, uint8_t* pDstV, int32_t iDstStride, uint8_t* pSrc, int32_t iSrcStride,
92+ int32_t iMvX, int32_t iMvY, int32_t iWidth, int32_t iHeight) {
93+ uint8_t* pSrcTmp;
94+ pSrc += (iMvY >> 3) * iSrcStride + (iMvX >> 3) * 2;
95+ pSrcTmp = &pSrc[iSrcStride];
2596
26−DEF_LUMA_MCTEST (Enc, 16, 8)
27−DEF_LUMA_MCTEST (Enc, 16, 16)
97+ int32_t iMvXIdx = iMvX & 0x07;
98+ int32_t iMvYIdx = iMvY & 0x07;
99+ int32_t iBiPara0 = (8 - iMvXIdx) * (8 - iMvYIdx);
100+ int32_t iBiPara1 = iMvXIdx * (8 - iMvYIdx);
101+ int32_t iBiPara2 = (8 - iMvXIdx) * iMvYIdx;
102+ int32_t iBiPara3 = iMvXIdx * iMvYIdx;
103+ for (int32_t y = 0; y < iHeight; y++) {
104+ for (int32_t x = 0; x < iWidth; x++) {
105+ pDstU[x] = (iBiPara0 * pSrc[2 * x] + iBiPara1 * pSrc[2 * x + 2] +
106+ iBiPara2 * pSrcTmp[2 * x] + iBiPara3 * pSrcTmp[2 * x + 2] + 32) >> 6;
107+ pDstV[x] = (iBiPara0 * pSrc[2 * x + 1] + iBiPara1 * pSrc[2 * x + 3] +
108+ iBiPara2 * pSrcTmp[2 * x + 1] + iBiPara3 * pSrcTmp[2 * x + 3] + 32) >> 6;
109+ }
110+ pSrc = pSrcTmp;
111+ pSrcTmp += iSrcStride;
112+ pDstU += iDstStride;
113+ pDstV += iDstStride;
114+ }
115+}
116+
117+/**********************MC Unit Test OPENH264 Code Begin******************************/
118+#define DEF_MCCOPYTEST(iW,iH) \
119+TEST(McCopy_c,iW##x##iH) \
120+{ \
121+ SMcFunc sMcFunc; \
122+ int32_t iCpuCores = 1; \
123+ uint32_t uiCpuFlag;\
124+ for(int32_t k =0; k<2; k++)\
125+ {\
126+ if(k==0)\
127+ {\
128+ uiCpuFlag = 0;\
129+ }else \
130+ {\
131+ uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores); \
132+ }\
133+ InitMcFunc(&sMcFunc, uiCpuFlag); \
134+ uint8_t uSrcAnchor[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE]; \
135+ uint8_t uSrcTest[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE]; \
136+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstAnchor, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
137+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstTest, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
138+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
139+ { \
140+ for(int32_t i=0;i<MC_BUFF_SRC_STRIDE;i++) \
141+ { \
142+ uSrcAnchor[j][i] = uSrcTest[j][i] = rand()%256; \
143+ } \
144+ } \
145+ memset(uDstAnchor,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE);\
146+ memset(uDstTest,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
147+ MCCopyAnchor(uSrcAnchor[0],MC_BUFF_SRC_STRIDE,uDstAnchor[0],MC_BUFF_DST_STRIDE,iW,iH); \
148+ sMcFunc.pMcLumaFunc(uSrcTest[0],MC_BUFF_SRC_STRIDE,uDstTest[0],MC_BUFF_DST_STRIDE,0,0,iW,iH); \
149+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
150+ { \
151+ for(int32_t i=0;i<MC_BUFF_DST_STRIDE;i++) \
152+ { \
153+ ASSERT_EQ(uDstAnchor[j][i],uDstTest[j][i]); \
154+ } \
155+ } \
156+ }\
157+}
158+
159+DEF_MCCOPYTEST (2, 2)
160+DEF_MCCOPYTEST (2, 4)
161+DEF_MCCOPYTEST (4, 2)
162+DEF_MCCOPYTEST (4, 4)
163+DEF_MCCOPYTEST (4, 8)
164+DEF_MCCOPYTEST (8, 4)
165+DEF_MCCOPYTEST (8, 8)
166+DEF_MCCOPYTEST (16, 8)
167+DEF_MCCOPYTEST (8, 16)
168+DEF_MCCOPYTEST (16, 16)
169+
170+#define DEF_LUMA_MCTEST(iW,iH) \
171+TEST(McHorVer,iW##x##iH) \
172+{ \
173+ for (int32_t a = 0; a < 4; a++) { \
174+ for (int32_t b = 0; b < 4; b++) { \
175+ SMcFunc sMcFunc; \
176+ uint8_t uSrcAnchor[4][MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE]; \
177+ uint8_t uSrcTest[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE]; \
178+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstAnchor, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
179+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstTest, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
180+ uint8_t* uSrcInputAnchor[4]; \
181+ int16_t pBuf[MC_BUFF_DST_STRIDE]; \
182+ uSrcInputAnchor[0] = &uSrcAnchor[0][4][4]; \
183+ uSrcInputAnchor[1] = &uSrcAnchor[1][4][4]; \
184+ uSrcInputAnchor[2] = &uSrcAnchor[2][4][4]; \
185+ uSrcInputAnchor[3] = &uSrcAnchor[3][4][4]; \
186+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
187+ {\
188+ for(int32_t i=0;i<MC_BUFF_SRC_STRIDE;i++) \
189+ {\
190+ uSrcAnchor[0][j][i] = uSrcTest[j][i] = rand()%256; \
191+ }\
192+ }\
193+ int32_t iCpuCores = 1; \
194+ uint32_t uiCpuFlag;\
195+ for(int32_t k =0; k<2; k++)\
196+ {\
197+ if(k==0)\
198+ {\
199+ uiCpuFlag = 0;\
200+ }else \
201+ {\
202+ uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores); \
203+ }\
204+ InitMcFunc(&sMcFunc,uiCpuFlag);\
205+ memset(uDstAnchor,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
206+ memset(uDstTest,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
207+ MCHalfPelFilterAnchor(uSrcInputAnchor[1],uSrcInputAnchor[2],uSrcInputAnchor[3],uSrcInputAnchor[0],MC_BUFF_SRC_STRIDE,iW+1,iH+1,pBuf+4); \
208+ MCLumaAnchor(uDstAnchor[0],MC_BUFF_DST_STRIDE,uSrcInputAnchor,MC_BUFF_SRC_STRIDE,a,b,iW,iH); \
209+ sMcFunc.pMcLumaFunc(&uSrcTest[4][4],MC_BUFF_SRC_STRIDE,uDstTest[0],MC_BUFF_DST_STRIDE,a,b,iW,iH);\
210+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
211+ { \
212+ for(int32_t i=0;i<MC_BUFF_DST_STRIDE;i++) \
213+ { \
214+ ASSERT_EQ(uDstAnchor[j][i],uDstTest[j][i]); \
215+ } \
216+ } \
217+ }\
218+ }\
219+ }\
220+}
221+
222+
223+DEF_LUMA_MCTEST (4, 4)
224+DEF_LUMA_MCTEST (4, 8)
225+DEF_LUMA_MCTEST (8, 4)
226+DEF_LUMA_MCTEST (8, 8)
227+DEF_LUMA_MCTEST (16, 8)
228+DEF_LUMA_MCTEST (8, 16)
229+DEF_LUMA_MCTEST (16, 16)
230+
231+#define DEF_CHROMA_MCTEST(iW,iH) \
232+TEST(McChroma,iW##x##iH) \
233+{ \
234+ for (int32_t a = 0; a < 8; a++) { \
235+ for (int32_t b = 0; b < 8; b++) { \
236+ SMcFunc sMcFunc; \
237+ uint8_t uSrcAnchor[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE*2]; \
238+ uint8_t uSrcTest[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE]; \
239+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstAnchor1, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
240+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstAnchor2, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
241+ ENFORCE_STACK_ALIGN_2D(uint8_t, uDstTest, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16); \
242+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
243+ {\
244+ for(int32_t i=0;i<MC_BUFF_SRC_STRIDE;i++) \
245+ {\
246+ uSrcAnchor[j][i*2] = uSrcTest[j][i] = rand()%256; \
247+ }\
248+ }\
249+ int32_t iCpuCores = 1; \
250+ uint32_t uiCpuFlag;\
251+ for(int32_t k =0; k<2; k++)\
252+ {\
253+ if(k==0)\
254+ {\
255+ uiCpuFlag = 0;\
256+ }else \
257+ {\
258+ uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores); \
259+ }\
260+ InitMcFunc(&sMcFunc,uiCpuFlag);\
261+ memset(uDstAnchor1,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
262+ memset(uDstAnchor2,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
263+ memset(uDstTest,0,sizeof(uint8_t)*MC_BUFF_HEIGHT*MC_BUFF_DST_STRIDE); \
264+ MCChromaAnchor(uDstAnchor1[0],uDstAnchor2[0],MC_BUFF_DST_STRIDE,uSrcAnchor[0],MC_BUFF_SRC_STRIDE*2,a,b,iW,iH); \
265+ sMcFunc.pMcChromaFunc(uSrcTest[0],MC_BUFF_SRC_STRIDE,uDstTest[0],MC_BUFF_DST_STRIDE,a,b,iW,iH);\
266+ for(int32_t j=0;j<MC_BUFF_HEIGHT;j++) \
267+ { \
268+ for(int32_t i=0;i<MC_BUFF_DST_STRIDE;i++) \
269+ { \
270+ ASSERT_EQ(uDstAnchor1[j][i],uDstTest[j][i]); \
271+ } \
272+ } \
273+ }\
274+ }\
275+ }\
276+}
28277
29−DEF_CHROMA_MCTEST (Enc, 4, 2)
30−DEF_CHROMA_MCTEST (Enc, 4, 4)
31−DEF_CHROMA_MCTEST (Enc, 4, 8)
32−DEF_CHROMA_MCTEST (Enc, 8, 4)
33−DEF_CHROMA_MCTEST (Enc, 8, 8)
278+DEF_CHROMA_MCTEST (2, 2)
279+DEF_CHROMA_MCTEST (2, 4)
280+DEF_CHROMA_MCTEST (4, 2)
281+DEF_CHROMA_MCTEST (4, 4)
282+DEF_CHROMA_MCTEST (4, 8)
283+DEF_CHROMA_MCTEST (8, 4)
284+DEF_CHROMA_MCTEST (8, 8)
34285
35286 TEST (EncMcAvg, PixelAvg) {
36287 SMcFunc sMcFunc;
@@ -39,7 +290,7 @@ TEST (EncMcAvg, PixelAvg) { · 2 unmodified lines
39290 int32_t width = 8 << w;
40291 int32_t height = 16;
41292 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);
42− WelsInitMcFuncs (&sMcFunc, uiCpuFlag);
293+ InitMcFunc (&sMcFunc, uiCpuFlag);
43294 uint8_t uSrc1[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];
44295 uint8_t uSrc2[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];
45296 ENFORCE_STACK_ALIGN_2D (uint8_t, uDstAnchor, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16);
@@ -52,8 +303,8 @@ TEST (EncMcAvg, PixelAvg) { · 6 unmodified lines
52303 }
53304 PixelAvgAnchor (uDstAnchor[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0], MC_BUFF_SRC_STRIDE, width,
54305 height);
55− sMcFunc.pfSampleAveraging[w] (uDstTest[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0],
56− MC_BUFF_SRC_STRIDE, height);
306+ sMcFunc.pfSampleAveraging (uDstTest[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0],
307+ MC_BUFF_SRC_STRIDE, width, height);
57308 for (int32_t j = 0; j < height; j++) {
58309 for (int32_t i = 0; i < width; i++) {
59310 ASSERT_EQ (uDstAnchor[j][i], uDstTest[j][i]);
@@ -88,7 +339,7 @@ TEST (EncMcHalfpel, LumaHalfpel) { · 28 unmodified lines
88339 }
89340
90341 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);
91− WelsInitMcFuncs (&sMcFunc, uiCpuFlag);
342+ InitMcFunc (&sMcFunc, uiCpuFlag);
92343
93344 MCHalfPelFilterAnchor (uAnchors[1], uAnchors[2], uAnchors[3], uAnchors[0], MC_BUFF_SRC_STRIDE, width + 1, height + 1, pBuf + 4);
94345 sMcFunc.pfLumaHalfpelHor (&uSrcTest[4][4], MC_BUFF_SRC_STRIDE, uDstTest[0], MC_BUFF_DST_STRIDE, width + 1, height);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t