Showing the changes to codec/processing/src (2 of 3 files). Show all
Unified · Split
| @@ -31,6 +31,8 @@ · 30 unmodified lines | |||
| 31 | */ | 31 | */ |
| 32 | 32 | ||
| 33 | #include "ComplexityAnalysis.h" | 33 | #include "ComplexityAnalysis.h" |
| 34 | #include "cpu.h" | ||
| 35 | #include "macros.h" | ||
| 34 | 36 | ||
| 35 | WELSVP_NAMESPACE_BEGIN | 37 | WELSVP_NAMESPACE_BEGIN |
| 36 | 38 | ||
| @@ -268,4 +270,201 @@ void CComplexityAnalysis::AnalyzeGomComplexityViaVar (SPixMap* pSrcPixMap, SPixM · 231 unmodified lines | |||
| 268 | } | 270 | } |
| 269 | 271 | ||
| 270 | 272 | ||
| 273 | CComplexityAnalysisScreen::CComplexityAnalysisScreen (int32_t iCpuFlag) { | ||
| 274 | m_eMethod = METHOD_COMPLEXITY_ANALYSIS_SCREEN; | ||
| 275 | WelsMemset (&m_ComplexityAnalysisParam, 0, sizeof (m_ComplexityAnalysisParam)); | ||
| 276 | |||
| 277 | m_pSadFunc = WelsSampleSad16x16_c; | ||
| 278 | m_pIntraFunc[0] = WelsI16x16LumaPredV_c; | ||
| 279 | m_pIntraFunc[1] = WelsI16x16LumaPredH_c; | ||
| 280 | #ifdef X86_ASM | ||
| 281 | if (iCpuFlag & WELS_CPU_SSE2) { | ||
| 282 | m_pSadFunc = WelsSampleSad16x16_sse2; | ||
| 283 | } | ||
| 284 | #endif | ||
| 285 | } | ||
| 286 | |||
| 287 | CComplexityAnalysisScreen::~CComplexityAnalysisScreen() { | ||
| 288 | } | ||
| 289 | |||
| 290 | EResult CComplexityAnalysisScreen::Process (int32_t nType, SPixMap* pSrc, SPixMap* pRef) { | ||
| 291 | bool bScrollFlag = m_ComplexityAnalysisParam.sScrollResult.bScrollDetectFlag; | ||
| 292 | int32_t iIdrFlag = m_ComplexityAnalysisParam.iIdrFlag; | ||
| 293 | int32_t iScrollMvX = m_ComplexityAnalysisParam.sScrollResult.iScrollMvX; | ||
| 294 | int32_t iScrollMvY = m_ComplexityAnalysisParam.sScrollResult.iScrollMvY; | ||
| 295 | |||
| 296 | if (m_ComplexityAnalysisParam.iMbRowInGom <= 0) | ||
| 297 | return RET_INVALIDPARAM; | ||
| 298 | if (!iIdrFlag && pRef == NULL) | ||
| 299 | return RET_INVALIDPARAM; | ||
| 300 | |||
| 301 | if (iIdrFlag || pRef == NULL) { | ||
| 302 | GomComplexityAnalysisIntra (pSrc); | ||
| 303 | } else if (!bScrollFlag || ((iScrollMvX == 0) && (iScrollMvY == 0))) { | ||
| 304 | GomComplexityAnalysisInter (pSrc, pRef, 0); | ||
| 305 | } else { | ||
| 306 | GomComplexityAnalysisInter (pSrc, pRef, 1);; | ||
| 307 | } | ||
| 308 | |||
| 309 | return RET_SUCCESS; | ||
| 310 | } | ||
| 311 | |||
| 312 | |||
| 313 | EResult CComplexityAnalysisScreen::Set (int32_t nType, void* pParam) { | ||
| 314 | if (pParam == NULL) | ||
| 315 | return RET_INVALIDPARAM; | ||
| 316 | |||
| 317 | m_ComplexityAnalysisParam = * (SComplexityAnalysisScreenParam*)pParam; | ||
| 318 | |||
| 319 | return RET_SUCCESS; | ||
| 320 | } | ||
| 321 | |||
| 322 | EResult CComplexityAnalysisScreen::Get (int32_t nType, void* pParam) { | ||
| 323 | if (pParam == NULL) | ||
| 324 | return RET_INVALIDPARAM; | ||
| 325 | |||
| 326 | * (SComplexityAnalysisScreenParam*)pParam = m_ComplexityAnalysisParam; | ||
| 327 | |||
| 328 | return RET_SUCCESS; | ||
| 329 | } | ||
| 330 | |||
| 331 | void CComplexityAnalysisScreen::GomComplexityAnalysisIntra (SPixMap* pSrc) { | ||
| 332 | int32_t iWidth = pSrc->sRect.iRectWidth; | ||
| 333 | int32_t iHeight = pSrc->sRect.iRectHeight; | ||
| 334 | int32_t iBlockWidth = iWidth >> 4; | ||
| 335 | int32_t iBlockHeight = iHeight >> 4; | ||
| 336 | |||
| 337 | int32_t iBlockSadH, iBlockSadV, iGomSad = 0; | ||
| 338 | int32_t iIdx = 0; | ||
| 339 | |||
| 340 | uint8_t* pPtrY = NULL; | ||
| 341 | int32_t iStrideY = 0; | ||
| 342 | int32_t iRowStrideY = 0; | ||
| 343 | |||
| 344 | uint8_t* pTmpCur = NULL; | ||
| 345 | |||
| 346 | ENFORCE_STACK_ALIGN_1D (uint8_t, iMemPredMb, 256, 16) | ||
| 347 | |||
| 348 | pPtrY = (uint8_t*)pSrc->pPixel[0]; | ||
| 349 | |||
| 350 | iStrideY = pSrc->iStride[0]; | ||
| 351 | iRowStrideY = iStrideY << 4; | ||
| 352 | |||
| 353 | m_ComplexityAnalysisParam.iFrameComplexity = 0; | ||
| 354 | |||
| 355 | for (int32_t j = 0; j < iBlockHeight; j ++) { | ||
| 356 | pTmpCur = pPtrY; | ||
| 357 | |||
| 358 | for (int32_t i = 0; i < iBlockWidth; i++) { | ||
| 359 | iBlockSadH = iBlockSadV = 0x7fffffff; // INT_MAX | ||
| 360 | if (j > 0) { | ||
| 361 | m_pIntraFunc[0] (iMemPredMb, pTmpCur, iStrideY); | ||
| 362 | iBlockSadH = m_pSadFunc (pTmpCur, iStrideY, iMemPredMb, 16); | ||
| 363 | } | ||
| 364 | if (i > 0) { | ||
| 365 | m_pIntraFunc[1] (iMemPredMb, pTmpCur, iStrideY); | ||
| 366 | iBlockSadV = m_pSadFunc (pTmpCur, iStrideY, iMemPredMb, 16); | ||
| 367 | } | ||
| 368 | if (i || j) | ||
| 369 | iGomSad += WELS_MIN (iBlockSadH, iBlockSadV); | ||
| 370 | |||
| 371 | pTmpCur += 16; | ||
| 372 | |||
| 373 | if (i == iBlockWidth - 1 && ((j + 1) % m_ComplexityAnalysisParam.iMbRowInGom == 0 || j == iBlockHeight - 1)) { | ||
| 374 | m_ComplexityAnalysisParam.pGomComplexity[iIdx] = iGomSad; | ||
| 375 | m_ComplexityAnalysisParam.iFrameComplexity += iGomSad; | ||
| 376 | iIdx++; | ||
| 377 | iGomSad = 0; | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | pPtrY += iRowStrideY; | ||
| 382 | } | ||
| 383 | m_ComplexityAnalysisParam.iGomNumInFrame = iIdx; | ||
| 384 | } | ||
| 385 | |||
| 386 | |||
| 387 | void CComplexityAnalysisScreen::GomComplexityAnalysisInter (SPixMap* pSrc, SPixMap* pRef, bool bScrollFlag) { | ||
| 388 | int32_t iWidth = pSrc->sRect.iRectWidth; | ||
| 389 | int32_t iHeight = pSrc->sRect.iRectHeight; | ||
| 390 | int32_t iBlockWidth = iWidth >> 4; | ||
| 391 | int32_t iBlockHeight = iHeight >> 4; | ||
| 392 | |||
| 393 | int32_t iInterSad, iScrollSad, iBlockSadH, iBlockSadV, iGomSad = 0; | ||
| 394 | int32_t iIdx = 0; | ||
| 395 | |||
| 396 | int32_t iScrollMvX = m_ComplexityAnalysisParam.sScrollResult.iScrollMvX; | ||
| 397 | int32_t iScrollMvY = m_ComplexityAnalysisParam.sScrollResult.iScrollMvY; | ||
| 398 | |||
| 399 | uint8_t* pPtrX = NULL, *pPtrY = NULL; | ||
| 400 | int32_t iStrideX = 0, iStrideY = 0; | ||
| 401 | int32_t iRowStrideX = 0, iRowStrideY = 0; | ||
| 402 | |||
| 403 | uint8_t* pTmpRef = NULL, *pTmpCur = NULL, *pTmpRefScroll = NULL; | ||
| 404 | |||
| 405 | ENFORCE_STACK_ALIGN_1D (uint8_t, iMemPredMb, 256, 16) | ||
| 406 | |||
| 407 | pPtrX = (uint8_t*)pRef->pPixel[0]; | ||
| 408 | pPtrY = (uint8_t*)pSrc->pPixel[0]; | ||
| 409 | |||
| 410 | iStrideX = pRef->iStride[0]; | ||
| 411 | iStrideY = pSrc->iStride[0]; | ||
| 412 | |||
| 413 | iRowStrideX = pRef->iStride[0] << 4; | ||
| 414 | iRowStrideY = pSrc->iStride[0] << 4; | ||
| 415 | |||
| 416 | m_ComplexityAnalysisParam.iFrameComplexity = 0; | ||
| 417 | |||
| 418 | for (int32_t j = 0; j < iBlockHeight; j ++) { | ||
| 419 | pTmpRef = pPtrX; | ||
| 420 | pTmpCur = pPtrY; | ||
| 421 | |||
| 422 | for (int32_t i = 0; i < iBlockWidth; i++) { | ||
| 423 | int32_t iBlockPointX = i << 4; | ||
| 424 | int32_t iBlockPointY = j << 4; | ||
| 425 | |||
| 426 | iInterSad = m_pSadFunc (pTmpCur, iStrideY, pTmpRef, iStrideX); | ||
| 427 | if (bScrollFlag) { | ||
| 428 | if ((iInterSad != 0) && | ||
| 429 | (iBlockPointX + iScrollMvX >= 0) && (iBlockPointX + iScrollMvX <= iWidth - 8) && | ||
| 430 | (iBlockPointY + iScrollMvY >= 0) && (iBlockPointY + iScrollMvY <= iHeight - 8)) { | ||
| 431 | pTmpRefScroll = pTmpRef - iScrollMvY * iStrideX + iScrollMvX; | ||
| 432 | iScrollSad = m_pSadFunc (pTmpCur, iStrideY, pTmpRefScroll, iStrideX); | ||
| 433 | |||
| 434 | if (iScrollSad < iInterSad) { | ||
| 435 | iInterSad = iScrollSad; | ||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | } | ||
| 440 | |||
| 441 | iBlockSadH = iBlockSadV = 0x7fffffff; // INT_MAX | ||
| 442 | |||
| 443 | if (j > 0) { | ||
| 444 | m_pIntraFunc[0] (iMemPredMb, pTmpCur, iStrideY); | ||
| 445 | iBlockSadH = m_pSadFunc (pTmpCur, iStrideY, iMemPredMb, 16); | ||
| 446 | } | ||
| 447 | if (i > 0) { | ||
| 448 | m_pIntraFunc[1] (iMemPredMb, pTmpCur, iStrideY); | ||
| 449 | iBlockSadV = m_pSadFunc (pTmpCur, iStrideY, iMemPredMb, 16); | ||
| 450 | } | ||
| 451 | |||
| 452 | iGomSad += WELS_MIN (WELS_MIN (iBlockSadH, iBlockSadV), iInterSad); | ||
| 453 | |||
| 454 | if (i == iBlockWidth - 1 && ((j + 1) % m_ComplexityAnalysisParam.iMbRowInGom == 0 || j == iBlockHeight - 1)) { | ||
| 455 | m_ComplexityAnalysisParam.pGomComplexity[iIdx] = iGomSad; | ||
| 456 | m_ComplexityAnalysisParam.iFrameComplexity += iGomSad; | ||
| 457 | iIdx++; | ||
| 458 | iGomSad = 0; | ||
| 459 | } | ||
| 460 | |||
| 461 | pTmpRef += 16; | ||
| 462 | pTmpCur += 16; | ||
| 463 | } | ||
| 464 | pPtrX += iRowStrideX; | ||
| 465 | pPtrY += iRowStrideY; | ||
| 466 | } | ||
| 467 | m_ComplexityAnalysisParam.iGomNumInFrame = iIdx; | ||
| 468 | } | ||
| 469 | |||
| 271 | WELSVP_NAMESPACE_END | 470 | WELSVP_NAMESPACE_END |
| @@ -46,6 +46,7 @@ · 45 unmodified lines | |||
| 46 | #include "memory.h" | 46 | #include "memory.h" |
| 47 | #include "WelsFrameWork.h" | 47 | #include "WelsFrameWork.h" |
| 48 | #include "IWelsVP.h" | 48 | #include "IWelsVP.h" |
| 49 | #include "common.h" | ||
| 49 | 50 | ||
| 50 | WELSVP_NAMESPACE_BEGIN | 51 | WELSVP_NAMESPACE_BEGIN |
| 51 | 52 | ||
| @@ -78,6 +79,30 @@ class CComplexityAnalysis : public IStrategy { · 26 unmodified lines | |||
| 78 | SComplexityAnalysisParam m_sComplexityAnalysisParam; | 79 | SComplexityAnalysisParam m_sComplexityAnalysisParam; |
| 79 | }; | 80 | }; |
| 80 | 81 | ||
| 82 | |||
| 83 | //for screen content | ||
| 84 | |||
| 85 | class CComplexityAnalysisScreen : public IStrategy | ||
| 86 | { | ||
| 87 | public: | ||
| 88 | CComplexityAnalysisScreen(int32_t cpu_flag); | ||
| 89 | ~CComplexityAnalysisScreen(); | ||
| 90 | |||
| 91 | EResult Process(int32_t nType, SPixMap *src, SPixMap *ref); | ||
| 92 | EResult Set(int32_t nType, void *pParam); | ||
| 93 | EResult Get(int32_t nType, void *pParam); | ||
| 94 | |||
| 95 | private: | ||
| 96 | void GomComplexityAnalysisIntra( SPixMap *pSrc ); | ||
| 97 | void GomComplexityAnalysisInter( SPixMap *pSrc, SPixMap *pRef,bool bScrollFlag); | ||
| 98 | |||
| 99 | private: | ||
| 100 | PSad16x16Func m_pSadFunc; | ||
| 101 | GetIntraPredPtr m_pIntraFunc[2]; | ||
| 102 | SComplexityAnalysisScreenParam m_ComplexityAnalysisParam; | ||
| 103 | }; | ||
| 104 | |||
| 105 | |||
| 81 | WELSVP_NAMESPACE_END | 106 | WELSVP_NAMESPACE_END |
| 82 | 107 | ||
| 83 | #endif | 108 | #endif |