All the tests of the line search (unoptimized and optimized) use the exact same copypasted structure. Instead factorize this into a test function which uses the provided function.
Showing the changes to test/encoder/EncUT_MotionEstimate.cpp (1 of 1 file). Show all
Unified · Split
| @@ -67,6 +67,7 @@ public: · 66 unmodified lines | |||
| 67 | m_pMvdCostTable=new uint16_t[52*m_uiMvdTableSize]; | 67 | m_pMvdCostTable=new uint16_t[52*m_uiMvdTableSize]; |
| 68 | ASSERT_TRUE( NULL != m_pMvdCostTable ); | 68 | ASSERT_TRUE( NULL != m_pMvdCostTable ); |
| 69 | } | 69 | } |
| 70 | void DoLineTest(PLineFullSearchFunc func, bool horizontal); | ||
| 70 | virtual void TearDown() { | 71 | virtual void TearDown() { |
| 71 | delete [] m_pMvdCostTable; | 72 | delete [] m_pMvdCostTable; |
| 72 | pMa->WelsFree( m_pRefData, "RefPic"); | 73 | pMa->WelsFree( m_pRefData, "RefPic"); |
| @@ -139,7 +140,7 @@ TEST_F(MotionEstimateTest, TestDiamondSearch) { · 66 unmodified lines | |||
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | 142 | ||
| 142 | TEST_F(MotionEstimateTest, TestVerticalSearch) { | 143 | void MotionEstimateTest::DoLineTest(PLineFullSearchFunc func, bool vertical) { |
| 143 | const int32_t kiMaxBlock16Sad = 72000;//a rough number | 144 | const int32_t kiMaxBlock16Sad = 72000;//a rough number |
| 144 | SWelsFuncPtrList sFuncList; | 145 | SWelsFuncPtrList sFuncList; |
| 145 | SWelsME sMe; | 146 | SWelsME sMe; |
| @@ -150,6 +151,7 @@ TEST_F(MotionEstimateTest, TestVerticalSearch) { · 4 unmodified lines | |||
| 150 | 151 | ||
| 151 | SMVUnitXY sTargetMv; | 152 | SMVUnitXY sTargetMv; |
| 152 | WelsInitSampleSadFunc( &sFuncList, 0 );//test c functions | 153 | WelsInitSampleSadFunc( &sFuncList, 0 );//test c functions |
| 154 | WelsInitMeFunc(&sFuncList, WelsCPUFeatureDetect(NULL), 1); | ||
| 153 | 155 | ||
| 154 | uint8_t *pRefPicCenter = m_pRefData+(m_iHeight/2)*m_iWidth+(m_iWidth/2); | 156 | uint8_t *pRefPicCenter = m_pRefData+(m_iHeight/2)*m_iWidth+(m_iWidth/2); |
| 155 | sMe.iCurMeBlockPixX = (m_iWidth/2); | 157 | sMe.iCurMeBlockPixX = (m_iWidth/2); |
| @@ -159,8 +161,13 @@ TEST_F(MotionEstimateTest, TestVerticalSearch) { · 3 unmodified lines | |||
| 159 | bool bFoundMatch = false; | 161 | bool bFoundMatch = false; |
| 160 | int32_t iTryTimes=100; | 162 | int32_t iTryTimes=100; |
| 161 | 163 | ||
| 162 | sTargetMv.iMvX = 0; | 164 | if (vertical) { |
| 163 | sTargetMv.iMvY = -sMe.iCurMeBlockPixY + INTPEL_NEEDED_MARGIN + rand()%(m_iHeight - 16 - 2*INTPEL_NEEDED_MARGIN); | 165 | sTargetMv.iMvX = 0; |
| 166 | sTargetMv.iMvY = -sMe.iCurMeBlockPixY + INTPEL_NEEDED_MARGIN + rand()%(m_iHeight - 16 - 2*INTPEL_NEEDED_MARGIN); | ||
| 167 | } else { | ||
| 168 | sTargetMv.iMvX = -sMe.iCurMeBlockPixX + INTPEL_NEEDED_MARGIN + rand()%(m_iWidth - 16 - 2*INTPEL_NEEDED_MARGIN); | ||
| 169 | sTargetMv.iMvY = 0; | ||
| 170 | } | ||
| 164 | bDataGeneratorSucceed = false; | 171 | bDataGeneratorSucceed = false; |
| 165 | bFoundMatch = false; | 172 | bFoundMatch = false; |
| 166 | while (!bFoundMatch && (iTryTimes--)>0) { | 173 | while (!bFoundMatch && (iTryTimes--)>0) { |
| @@ -183,16 +190,24 @@ TEST_F(MotionEstimateTest, TestVerticalSearch) { · 16 unmodified lines | |||
| 183 | const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2); | 190 | const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2); |
| 184 | uint16_t* pMvdCostX = sMe.pMvdCost - iCurMeBlockQpelPixX - sMe.sMvp.iMvX; //do the offset here | 191 | uint16_t* pMvdCostX = sMe.pMvdCost - iCurMeBlockQpelPixX - sMe.sMvp.iMvX; //do the offset here |
| 185 | uint16_t* pMvdCostY = sMe.pMvdCost - iCurMeBlockQpelPixY - sMe.sMvp.iMvY; | 192 | uint16_t* pMvdCostY = sMe.pMvdCost - iCurMeBlockQpelPixY - sMe.sMvp.iMvY; |
| 186 | LineFullSearch_c ( &sFuncList, &sMe, | 193 | uint16_t* pMvdCost = vertical ? pMvdCostY : pMvdCostX; |
| 187 | pMvdCostY, pMvdCostX[ iCurMeBlockQpelPixX ], | 194 | int iSize = vertical ? m_iHeight : m_iWidth; |
| 188 | m_iMaxSearchBlock, m_iWidth, | 195 | int iFixedMvd = vertical ? pMvdCostX[ iCurMeBlockQpelPixX ] : pMvdCostY[ iCurMeBlockQpelPixY ]; |
| 189 | INTPEL_NEEDED_MARGIN, | 196 | func ( &sFuncList, &sMe, |
| 190 | m_iHeight-INTPEL_NEEDED_MARGIN-16, true ); | 197 | pMvdCost, iFixedMvd, |
| 198 | m_iMaxSearchBlock, m_iWidth, | ||
| 199 | INTPEL_NEEDED_MARGIN, | ||
| 200 | iSize-INTPEL_NEEDED_MARGIN-16, vertical ); | ||
| 191 | 201 | ||
| 192 | //the last selection may be affected by MVDcost, that is when smaller MvY will be better | 202 | //the last selection may be affected by MVDcost, that is when smaller MvY will be better |
| 193 | bFoundMatch = (sMe.sMv.iMvX==0 | 203 | if (vertical) { |
| 194 | &&(sMe.sMv.iMvY==sTargetMv.iMvY||abs(sMe.sMv.iMvY)<abs(sTargetMv.iMvY))); | 204 | bFoundMatch = (sMe.sMv.iMvX==0 |
| 195 | //printf("TestVerticalSearch Target: %d,%d\n", sTargetMv.iMvX, sTargetMv.iMvY); | 205 | &&(sMe.sMv.iMvY==sTargetMv.iMvY||abs(sMe.sMv.iMvY)<abs(sTargetMv.iMvY))); |
| 206 | } else { | ||
| 207 | bFoundMatch = (sMe.sMv.iMvY==0 | ||
| 208 | &&(sMe.sMv.iMvX==sTargetMv.iMvX||abs(sMe.sMv.iMvX)<abs(sTargetMv.iMvX))); | ||
| 209 | } | ||
| 210 | //printf("DoLineTest Target: %d,%d\n", sTargetMv.iMvX, sTargetMv.iMvY); | ||
| 196 | } | 211 | } |
| 197 | if (bDataGeneratorSucceed) { | 212 | if (bDataGeneratorSucceed) { |
| 198 | //if DataGenerator never succeed, there is no meaning to check iTryTimes | 213 | //if DataGenerator never succeed, there is no meaning to check iTryTimes |
| @@ -200,199 +215,31 @@ TEST_F(MotionEstimateTest, TestVerticalSearch) { · 1 unmodified line | |||
| 200 | //it is possible that ref at differnt position is identical, but that should be under a low probability | 215 | //it is possible that ref at differnt position is identical, but that should be under a low probability |
| 201 | } | 216 | } |
| 202 | } | 217 | } |
| 203 | TEST_F(MotionEstimateTest, TestHorizontalSearch) { | ||
| 204 | const int32_t kiMaxBlock16Sad = 72000;//a rough number | ||
| 205 | SWelsFuncPtrList sFuncList; | ||
| 206 | SWelsME sMe; | ||
| 207 | |||
| 208 | srand((uint32_t)time(NULL)); | ||
| 209 | const uint8_t kuiQp = rand()%52; | ||
| 210 | InitMe(kuiQp, 648, m_uiMvdTableSize, m_pMvdCostTable, &sMe); | ||
| 211 | |||
| 212 | SMVUnitXY sTargetMv; | ||
| 213 | WelsInitSampleSadFunc( &sFuncList, 0 );//test c functions | ||
| 214 | |||
| 215 | uint8_t *pRefPicCenter = m_pRefData+(m_iHeight/2)*m_iWidth+(m_iWidth/2); | ||
| 216 | sMe.iCurMeBlockPixX = (m_iWidth/2); | ||
| 217 | sMe.iCurMeBlockPixY = (m_iHeight/2); | ||
| 218 | |||
| 219 | bool bDataGeneratorSucceed = false; | ||
| 220 | bool bFoundMatch = false; | ||
| 221 | int32_t iTryTimes=100; | ||
| 222 | |||
| 223 | sTargetMv.iMvX = -sMe.iCurMeBlockPixX + INTPEL_NEEDED_MARGIN + rand()%(m_iWidth - 16 - 2*INTPEL_NEEDED_MARGIN); | ||
| 224 | sTargetMv.iMvY = 0; | ||
| 225 | bDataGeneratorSucceed = false; | ||
| 226 | bFoundMatch = false; | ||
| 227 | while (!bFoundMatch && (iTryTimes--)>0) { | ||
| 228 | if (!YUVPixelDataGenerator( m_pRefData, m_iWidth, m_iHeight, m_iWidth )) | ||
| 229 | continue; | ||
| 230 | |||
| 231 | bDataGeneratorSucceed = true; | ||
| 232 | CopyTargetBlock( m_pSrcBlock, 16, sTargetMv, m_iWidth, pRefPicCenter); | ||
| 233 | |||
| 234 | //clean the sMe status | ||
| 235 | sMe.uiBlockSize = rand()%5; | ||
| 236 | sMe.pEncMb = m_pSrcBlock; | ||
| 237 | sMe.pRefMb = pRefPicCenter; | ||
| 238 | sMe.pColoRefMb = pRefPicCenter; | ||
| 239 | sMe.sMv.iMvX = sMe.sMv.iMvY = 0; | ||
| 240 | sMe.uiSadCost = sMe.uiSatdCost = kiMaxBlock16Sad; | ||
| 241 | const int32_t iCurMeBlockPixX = sMe.iCurMeBlockPixX; | ||
| 242 | const int32_t iCurMeBlockQpelPixX = ((iCurMeBlockPixX)<<2); | ||
| 243 | const int32_t iCurMeBlockPixY = sMe.iCurMeBlockPixY; | ||
| 244 | const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2); | ||
| 245 | uint16_t* pMvdCostX = sMe.pMvdCost - iCurMeBlockQpelPixX - sMe.sMvp.iMvX; //do the offset here | ||
| 246 | uint16_t* pMvdCostY = sMe.pMvdCost - iCurMeBlockQpelPixY - sMe.sMvp.iMvY; | ||
| 247 | LineFullSearch_c ( &sFuncList, &sMe, | ||
| 248 | pMvdCostX, pMvdCostY[ iCurMeBlockQpelPixY ], | ||
| 249 | m_iMaxSearchBlock, m_iWidth, | ||
| 250 | INTPEL_NEEDED_MARGIN, | ||
| 251 | m_iWidth-INTPEL_NEEDED_MARGIN-16, false ); | ||
| 252 | 218 | ||
| 253 | //the last selection may be affected by MVDcost, that is when smaller MvY will be better | 219 | TEST_F(MotionEstimateTest, TestVerticalSearch) { |
| 254 | bFoundMatch = (sMe.sMv.iMvY==0 | 220 | DoLineTest(LineFullSearch_c, true); |
| 255 | &&(sMe.sMv.iMvX==sTargetMv.iMvX||abs(sMe.sMv.iMvX)<abs(sTargetMv.iMvX))); | 221 | } |
| 256 | //printf("TestHorizontalSearch Target: %d,%d\n", sTargetMv.iMvX, sTargetMv.iMvY); | 222 | TEST_F(MotionEstimateTest, TestHorizontalSearch) { |
| 257 | } | 223 | DoLineTest(LineFullSearch_c, false); |
| 258 | if (bDataGeneratorSucceed) { | ||
| 259 | //if DataGenerator never succeed, there is no meaning to check iTryTimes | ||
| 260 | ASSERT_TRUE(iTryTimes > 0); | ||
| 261 | //it is possible that ref at differnt position is identical, but that should be under a low probability | ||
| 262 | } | ||
| 263 | } | 224 | } |
| 264 | 225 | ||
| 265 | #ifdef X86_ASM | 226 | #ifdef X86_ASM |
| 266 | TEST_F(MotionEstimateTest, TestVerticalSearch_SSE41) | 227 | TEST_F(MotionEstimateTest, TestVerticalSearch_SSE41) |
| 267 | { | 228 | { |
| 268 | const int32_t kiMaxBlock16Sad = 72000;//a rough number | ||
| 269 | SWelsFuncPtrList sFuncList; | ||
| 270 | SWelsME sMe; | ||
| 271 | |||
| 272 | srand((uint32_t)time(NULL)); | ||
| 273 | const uint8_t kuiQp = rand()%52; | ||
| 274 | InitMe(kuiQp, 648, m_uiMvdTableSize, m_pMvdCostTable, &sMe); | ||
| 275 | int32_t iTmp = 1; | 229 | int32_t iTmp = 1; |
| 276 | uint32_t uiCPUFlags = WelsCPUFeatureDetect( &iTmp); | 230 | uint32_t uiCPUFlags = WelsCPUFeatureDetect( &iTmp); |
| 277 | if ((uiCPUFlags & WELS_CPU_SSE41) == 0) return ; | 231 | if ((uiCPUFlags & WELS_CPU_SSE41) == 0) return ; |
| 278 | 232 | ||
| 279 | SMVUnitXY sTargetMv; | 233 | DoLineTest(VerticalFullSearchUsingSSE41, true); |
| 280 | WelsInitSampleSadFunc( &sFuncList, 0 );//test c functions | ||
| 281 | WelsInitMeFunc(&sFuncList, WELS_CPU_SSE41, 1); | ||
| 282 | |||
| 283 | uint8_t *pRefPicCenter = m_pRefData+(m_iHeight/2)*m_iWidth+(m_iWidth/2); | ||
| 284 | sMe.iCurMeBlockPixX = (m_iWidth/2); | ||
| 285 | sMe.iCurMeBlockPixY = (m_iHeight/2); | ||
| 286 | |||
| 287 | bool bDataGeneratorSucceed = false; | ||
| 288 | bool bFoundMatch = false; | ||
| 289 | int32_t iTryTimes=100; | ||
| 290 | |||
| 291 | sTargetMv.iMvX = 0; | ||
| 292 | sTargetMv.iMvY = -sMe.iCurMeBlockPixY + INTPEL_NEEDED_MARGIN + rand()%(m_iHeight - 16 - 2*INTPEL_NEEDED_MARGIN); | ||
| 293 | bDataGeneratorSucceed = false; | ||
| 294 | bFoundMatch = false; | ||
| 295 | while (!bFoundMatch && (iTryTimes--)>0) { | ||
| 296 | if (!YUVPixelDataGenerator( m_pRefData, m_iWidth, m_iHeight, m_iWidth )) | ||
| 297 | continue; | ||
| 298 | |||
| 299 | bDataGeneratorSucceed = true; | ||
| 300 | CopyTargetBlock( m_pSrcBlock, 16, sTargetMv, m_iWidth, pRefPicCenter); | ||
| 301 | |||
| 302 | //clean the sMe status | ||
| 303 | sMe.uiBlockSize = rand()%5; | ||
| 304 | sMe.pEncMb = m_pSrcBlock; | ||
| 305 | sMe.pRefMb = pRefPicCenter; | ||
| 306 | sMe.pColoRefMb = pRefPicCenter; | ||
| 307 | sMe.sMv.iMvX = sMe.sMv.iMvY = 0; | ||
| 308 | sMe.uiSadCost = sMe.uiSatdCost = kiMaxBlock16Sad; | ||
| 309 | const int32_t iCurMeBlockPixX = sMe.iCurMeBlockPixX; | ||
| 310 | const int32_t iCurMeBlockQpelPixX = ((iCurMeBlockPixX)<<2); | ||
| 311 | const int32_t iCurMeBlockPixY = sMe.iCurMeBlockPixY; | ||
| 312 | const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2); | ||
| 313 | uint16_t* pMvdCostX = sMe.pMvdCost - iCurMeBlockQpelPixX - sMe.sMvp.iMvX; //do the offset here | ||
| 314 | uint16_t* pMvdCostY = sMe.pMvdCost - iCurMeBlockQpelPixY - sMe.sMvp.iMvY; | ||
| 315 | VerticalFullSearchUsingSSE41 ( &sFuncList, &sMe, | ||
| 316 | pMvdCostY, pMvdCostX[ iCurMeBlockQpelPixX ], | ||
| 317 | m_iMaxSearchBlock, m_iWidth, | ||
| 318 | INTPEL_NEEDED_MARGIN, | ||
| 319 | m_iHeight-INTPEL_NEEDED_MARGIN-16, true ); | ||
| 320 | |||
| 321 | //the last selection may be affected by MVDcost, that is when smaller MvY will be better | ||
| 322 | bFoundMatch = (sMe.sMv.iMvX==0 | ||
| 323 | &&(sMe.sMv.iMvY==sTargetMv.iMvY||abs(sMe.sMv.iMvY)<abs(sTargetMv.iMvY))); | ||
| 324 | //printf("TestVerticalSearch Target: %d,%d\n", sTargetMv.iMvX, sTargetMv.iMvY); | ||
| 325 | } | ||
| 326 | if (bDataGeneratorSucceed) { | ||
| 327 | //if DataGenerator never succeed, there is no meaning to check iTryTimes | ||
| 328 | ASSERT_TRUE(iTryTimes > 0); | ||
| 329 | //it is possible that ref at differnt position is identical, but that should be under a low probability | ||
| 330 | } | ||
| 331 | } | 234 | } |
| 332 | 235 | ||
| 333 | TEST_F(MotionEstimateTest, TestHorizontalSearch_SSE41) | 236 | TEST_F(MotionEstimateTest, TestHorizontalSearch_SSE41) |
| 334 | { | 237 | { |
| 335 | const int32_t kiMaxBlock16Sad = 72000;//a rough number | ||
| 336 | SWelsFuncPtrList sFuncList; | ||
| 337 | SWelsME sMe; | ||
| 338 | |||
| 339 | srand((uint32_t)time(NULL)); | ||
| 340 | const uint8_t kuiQp = rand()%52; | ||
| 341 | InitMe(kuiQp, 648, m_uiMvdTableSize, m_pMvdCostTable, &sMe); | ||
| 342 | int32_t iTmp = 1; | 238 | int32_t iTmp = 1; |
| 343 | uint32_t uiCPUFlags = WelsCPUFeatureDetect( &iTmp); | 239 | uint32_t uiCPUFlags = WelsCPUFeatureDetect( &iTmp); |
| 344 | if ((uiCPUFlags & WELS_CPU_SSE41) == 0) return ; | 240 | if ((uiCPUFlags & WELS_CPU_SSE41) == 0) return ; |
| 345 | SMVUnitXY sTargetMv; | ||
| 346 | WelsInitSampleSadFunc( &sFuncList, 0 );//test c functions | ||
| 347 | WelsInitMeFunc(&sFuncList, WELS_CPU_SSE41, 1); | ||
| 348 | |||
| 349 | uint8_t *pRefPicCenter = m_pRefData+(m_iHeight/2)*m_iWidth+(m_iWidth/2); | ||
| 350 | sMe.iCurMeBlockPixX = (m_iWidth/2); | ||
| 351 | sMe.iCurMeBlockPixY = (m_iHeight/2); | ||
| 352 | |||
| 353 | bool bDataGeneratorSucceed = false; | ||
| 354 | bool bFoundMatch = false; | ||
| 355 | int32_t iTryTimes=100; | ||
| 356 | |||
| 357 | sTargetMv.iMvX = -sMe.iCurMeBlockPixX + INTPEL_NEEDED_MARGIN + rand()%(m_iWidth - 16 - 2*INTPEL_NEEDED_MARGIN); | ||
| 358 | sTargetMv.iMvY = 0; | ||
| 359 | bDataGeneratorSucceed = false; | ||
| 360 | bFoundMatch = false; | ||
| 361 | while (!bFoundMatch && (iTryTimes--)>0) { | ||
| 362 | if (!YUVPixelDataGenerator( m_pRefData, m_iWidth, m_iHeight, m_iWidth )) | ||
| 363 | continue; | ||
| 364 | bDataGeneratorSucceed = true; | ||
| 365 | CopyTargetBlock( m_pSrcBlock, m_iMaxSearchBlock, sTargetMv, m_iWidth, pRefPicCenter ); | ||
| 366 | |||
| 367 | //clean sMe status | ||
| 368 | sMe.uiBlockSize = rand()%5; | ||
| 369 | sMe.pEncMb = m_pSrcBlock; | ||
| 370 | sMe.pRefMb = pRefPicCenter; | ||
| 371 | sMe.pColoRefMb = pRefPicCenter; | ||
| 372 | sMe.sMv.iMvX = sMe.sMv.iMvY = 0; | ||
| 373 | sMe.uiSadCost = sMe.uiSatdCost = kiMaxBlock16Sad; | ||
| 374 | const int32_t iCurMeBlockPixX = sMe.iCurMeBlockPixX; | ||
| 375 | const int32_t iCurMeBlockQpelPixX = ((iCurMeBlockPixX)<<2); | ||
| 376 | const int32_t iCurMeBlockPixY = sMe.iCurMeBlockPixY; | ||
| 377 | const int32_t iCurMeBlockQpelPixY = ((iCurMeBlockPixY)<<2); | ||
| 378 | uint16_t* pMvdCostX = sMe.pMvdCost - iCurMeBlockQpelPixX - sMe.sMvp.iMvX; //do the offset here | ||
| 379 | uint16_t* pMvdCostY = sMe.pMvdCost - iCurMeBlockQpelPixY - sMe.sMvp.iMvY; | ||
| 380 | HorizontalFullSearchUsingSSE41 ( &sFuncList, &sMe, | ||
| 381 | pMvdCostX, pMvdCostY[ iCurMeBlockQpelPixY ], | ||
| 382 | m_iMaxSearchBlock, m_iWidth, | ||
| 383 | INTPEL_NEEDED_MARGIN, | ||
| 384 | m_iWidth-INTPEL_NEEDED_MARGIN-16, false ); | ||
| 385 | 241 | ||
| 386 | //the last selection may be affected by MVDcost, that is when smaller MvY will be better | 242 | DoLineTest(HorizontalFullSearchUsingSSE41, false); |
| 387 | bFoundMatch = (sMe.sMv.iMvY==0 | ||
| 388 | &&(sMe.sMv.iMvX==sTargetMv.iMvX||abs(sMe.sMv.iMvX)<abs(sTargetMv.iMvX))); | ||
| 389 | //printf("TestHorizontalSearch Target: %d,%d\n", sTargetMv.iMvX, sTargetMv.iMvY); | ||
| 390 | } | ||
| 391 | if (bDataGeneratorSucceed) { | ||
| 392 | //if DataGenerator never succeed, there is no meaning to check iTryTimes | ||
| 393 | ASSERT_TRUE(iTryTimes > 0); | ||
| 394 | //it is possible that ref at differnt position is identical, but that should be under a low probability | ||
| 395 | } | ||
| 396 | } | 243 | } |
| 397 | #endif | 244 | #endif |
| 398 | 245 | ||