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 @@
1#include <gtest/gtest.h>1#include <gtest/gtest.h>
2#include "codec_def.h"2#include "codec_def.h"
3#include "macros.h"
3#include "mc.h"4#include "mc.h"
4#include "cpu.h"5#include "cpu.h"
5using namespace WelsEnc;6using namespace WelsCommon;
6 7
7static void McLumaFunc (SMcFunc* pFuncs, const uint8_t* pSrc, int32_t iSrcStride, uint8_t* pDst, int32_t iDstStride,8#define MC_BUFF_SRC_STRIDE 32
8 int16_t iMvX, int16_t iMvY, int32_t iWidth, int32_t iHeight) {9#define MC_BUFF_DST_STRIDE 32
9 uint8_t uiMvpIdx = ((iMvY & 0x03) << 2) + (iMvX & 0x03);10#define MC_BUFF_HEIGHT 30
10 ASSERT_EQ (iWidth, 16);11
11 pFuncs->pfLumaQuarpelMc[uiMvpIdx] (pSrc, iSrcStride, pDst, iDstStride, iHeight);12/**********************MC Unit Test Anchor Code Begin******************************/
13static 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};
19static 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};
25static 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]))
32static inline uint8_t Clip255 (int32_t x) {
33 return ((x & ~255) ? (-x) >> 31 & 255 : x);
34}
35
36static 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 }
12}43}
13 44
14#define InitMcFunc WelsInitMcFuncs45static 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}
15 63
16#define LUMA_FUNC(funcs, src, srcstride, dst, dststride, mvx, mvy, width, height) \64static void PixelAvgAnchor (uint8_t* pDst, int32_t iDstStride,
17 McLumaFunc (funcs, src, srcstride, dst, dststride, mvx, mvy, width, height)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}
18 75
19#define CHROMA_FUNC sMcFunc.pfChromaMc76static 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;
20 82
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}
22 90
23DEF_MCCOPYTEST (Enc, 16, 8)91static void MCChromaAnchor (uint8_t* pDstU, uint8_t* pDstV, int32_t iDstStride, uint8_t* pSrc, int32_t iSrcStride,
24DEF_MCCOPYTEST (Enc, 16, 16)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];
25 96
26DEF_LUMA_MCTEST (Enc, 16, 8)97 int32_t iMvXIdx = iMvX & 0x07;
27DEF_LUMA_MCTEST (Enc, 16, 16)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) \
119TEST(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
159DEF_MCCOPYTEST (2, 2)
160DEF_MCCOPYTEST (2, 4)
161DEF_MCCOPYTEST (4, 2)
162DEF_MCCOPYTEST (4, 4)
163DEF_MCCOPYTEST (4, 8)
164DEF_MCCOPYTEST (8, 4)
165DEF_MCCOPYTEST (8, 8)
166DEF_MCCOPYTEST (16, 8)
167DEF_MCCOPYTEST (8, 16)
168DEF_MCCOPYTEST (16, 16)
169
170#define DEF_LUMA_MCTEST(iW,iH) \
171TEST(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
223DEF_LUMA_MCTEST (4, 4)
224DEF_LUMA_MCTEST (4, 8)
225DEF_LUMA_MCTEST (8, 4)
226DEF_LUMA_MCTEST (8, 8)
227DEF_LUMA_MCTEST (16, 8)
228DEF_LUMA_MCTEST (8, 16)
229DEF_LUMA_MCTEST (16, 16)
230
231#define DEF_CHROMA_MCTEST(iW,iH) \
232TEST(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}
28 277
29DEF_CHROMA_MCTEST (Enc, 4, 2)278DEF_CHROMA_MCTEST (2, 2)
30DEF_CHROMA_MCTEST (Enc, 4, 4)279DEF_CHROMA_MCTEST (2, 4)
31DEF_CHROMA_MCTEST (Enc, 4, 8)280DEF_CHROMA_MCTEST (4, 2)
32DEF_CHROMA_MCTEST (Enc, 8, 4)281DEF_CHROMA_MCTEST (4, 4)
33DEF_CHROMA_MCTEST (Enc, 8, 8)282DEF_CHROMA_MCTEST (4, 8)
283DEF_CHROMA_MCTEST (8, 4)
284DEF_CHROMA_MCTEST (8, 8)
34 285
35TEST (EncMcAvg, PixelAvg) {286TEST (EncMcAvg, PixelAvg) {
36 SMcFunc sMcFunc;287 SMcFunc sMcFunc;
@@ -39,7 +290,7 @@ TEST (EncMcAvg, PixelAvg) { · 2 unmodified lines
39 int32_t width = 8 << w;290 int32_t width = 8 << w;
40 int32_t height = 16;291 int32_t height = 16;
41 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);292 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);
42 WelsInitMcFuncs (&sMcFunc, uiCpuFlag);293 InitMcFunc (&sMcFunc, uiCpuFlag);
43 uint8_t uSrc1[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];294 uint8_t uSrc1[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];
44 uint8_t uSrc2[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];295 uint8_t uSrc2[MC_BUFF_HEIGHT][MC_BUFF_SRC_STRIDE];
45 ENFORCE_STACK_ALIGN_2D (uint8_t, uDstAnchor, MC_BUFF_HEIGHT, MC_BUFF_DST_STRIDE, 16);296 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
52 }303 }
53 PixelAvgAnchor (uDstAnchor[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0], MC_BUFF_SRC_STRIDE, width,304 PixelAvgAnchor (uDstAnchor[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0], MC_BUFF_SRC_STRIDE, width,
54 height);305 height);
55 sMcFunc.pfSampleAveraging[w] (uDstTest[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0],306 sMcFunc.pfSampleAveraging (uDstTest[0], MC_BUFF_DST_STRIDE, uSrc1[0], MC_BUFF_SRC_STRIDE, uSrc2[0],
56 MC_BUFF_SRC_STRIDE, height);307 MC_BUFF_SRC_STRIDE, width, height);
57 for (int32_t j = 0; j < height; j++) {308 for (int32_t j = 0; j < height; j++) {
58 for (int32_t i = 0; i < width; i++) {309 for (int32_t i = 0; i < width; i++) {
59 ASSERT_EQ (uDstAnchor[j][i], uDstTest[j][i]);310 ASSERT_EQ (uDstAnchor[j][i], uDstTest[j][i]);
@@ -88,7 +339,7 @@ TEST (EncMcHalfpel, LumaHalfpel) { · 28 unmodified lines
88 }339 }
89 340
90 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);341 uint32_t uiCpuFlag = k == 0 ? 0 : WelsCPUFeatureDetect (NULL);
91 WelsInitMcFuncs (&sMcFunc, uiCpuFlag);342 InitMcFunc (&sMcFunc, uiCpuFlag);
92 343
93 MCHalfPelFilterAnchor (uAnchors[1], uAnchors[2], uAnchors[3], uAnchors[0], MC_BUFF_SRC_STRIDE, width + 1, height + 1, pBuf + 4);344 MCHalfPelFilterAnchor (uAnchors[1], uAnchors[2], uAnchors[3], uAnchors[0], MC_BUFF_SRC_STRIDE, width + 1, height + 1, pBuf + 4);
94 sMcFunc.pfLumaHalfpelHor (&uSrcTest[4][4], MC_BUFF_SRC_STRIDE, uDstTest[0], MC_BUFF_DST_STRIDE, width + 1, height);345 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