shithub: openh264

Download patch

ref: c0d21a23f373abfd42b0ea0f5c7629683159ad99
parent: c65e2860361c8df6d0223f4c5ec470ceb4862426
parent: 34ad719cf2afacc3ce8ff826d4ebd50aa87dda67
author: huili2 <huili2@cisco.com>
date: Fri Apr 25 11:07:15 EDT 2014

Merge pull request #745 from lyao2/scrollingUT

add scroll detection UT

diff: cannot open b/test/processing//null: file does not exist: 'b/test/processing//null'
--- a/Makefile
+++ b/Makefile
@@ -70,7 +70,8 @@
 
 PROCESSING_INCLUDES = \
     -Icodec/processing/interface \
-    -Icodec/processing/src/common
+    -Icodec/processing/src/common \
+    -Icodec/processing/src/scrolldetection
 
 GTEST_INCLUDES += \
     -Igtest \
@@ -92,6 +93,7 @@
 CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
 DECODER_UNITTEST_INCLUDES = $(CODEC_UNITTEST_INCLUDES) $(DECODER_INCLUDES) -Itest -Itest/decoder
 ENCODER_UNITTEST_INCLUDES = $(CODEC_UNITTEST_INCLUDES) $(ENCODER_INCLUDES) -Itest -Itest/encoder
+PROCESSING_UNITTEST_INCLUDES = $(CODEC_UNITTEST_INCLUDES) $(PROCESSING_INCLUDES) -Itest -Itest/processing
 API_TEST_INCLUDES = $(CODEC_UNITTEST_INCLUDES) -Itest -Itest/api
 .PHONY: test gtest-bootstrap clean
 
@@ -158,9 +160,10 @@
 include test/api/targets.mk
 include test/decoder/targets.mk
 include test/encoder/targets.mk
+include test/processing/targets.mk
 binaries: codec_unittest$(EXEEXT)
 BINARIES += codec_unittest$(EXEEXT)
-codec_unittest$(EXEEXT): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(API_TEST_OBJS) $(CODEC_UNITTEST_DEPS)
+codec_unittest$(EXEEXT): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(API_TEST_OBJS) $(CODEC_UNITTEST_DEPS)
 	$(QUIET)rm -f $@
 	$(QUIET_CXX)$(CXX) $(CXX_LINK_O) $+ $(CODEC_UNITTEST_LDFLAGS) $(LDFLAGS)
 endif
--- a/build/mktargets.sh
+++ b/build/mktargets.sh
@@ -9,5 +9,6 @@
 python build/mktargets.py --directory codec/console/enc --binary h264enc
 python build/mktargets.py --directory test/encoder --prefix encoder_unittest
 python build/mktargets.py --directory test/decoder --prefix decoder_unittest
+python build/mktargets.py --directory test/processing --prefix processing_unittest
 python build/mktargets.py --directory test/api --prefix api_test
 python build/mktargets.py --directory gtest --library gtest --out build/gtest-targets.mk --cpp-suffix .cc --include gtest-all.cc
--- a/codec/processing/src/scrolldetection/ScrollDetection.cpp
+++ b/codec/processing/src/scrolldetection/ScrollDetection.cpp
@@ -38,9 +38,8 @@
 WELSVP_NAMESPACE_BEGIN
 
 EResult CScrollDetection::Process(int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap){
-  if (pRefPixMap->pPixel[0] == NULL || pRefPixMap->pPixel[1] == NULL || pRefPixMap->pPixel[2] == NULL
-    || pSrcPixMap->pPixel[0] == NULL || pSrcPixMap->pPixel[1] == NULL || pSrcPixMap->pPixel[2] == NULL
-    || pRefPixMap->sRect.iRectWidth != pSrcPixMap->sRect.iRectWidth || pRefPixMap->sRect.iRectHeight != pSrcPixMap->sRect.iRectHeight){
+  if (pRefPixMap->pPixel[0] == NULL || pSrcPixMap->pPixel[0] == NULL ||
+    pRefPixMap->sRect.iRectWidth != pSrcPixMap->sRect.iRectWidth || pRefPixMap->sRect.iRectHeight != pSrcPixMap->sRect.iRectHeight){
   return RET_INVALIDPARAM;
   }
 
--- /dev/null
+++ b/test/processing/ProcessUT_ScrollDetection.cpp
@@ -1,0 +1,84 @@
+#include <gtest/gtest.h>
+#include <math.h>
+#include <string.h>
+#include "cpu.h"
+#include "cpu_core.h"
+#include "typedef.h"
+#include "IWelsVP.h"
+#include "ScrollDetection.h"
+#include "ScrollDetectionFuncs.h"
+#include "utils/DataGenerator.h"
+
+using namespace nsWelsVP;
+
+#define ASSERT_MEMORY_FAIL2X(A, B)     \
+  if (NULL == B) {                     \
+  delete []A;\
+  ASSERT_TRUE(0);                    \
+  }
+
+TEST(ScrollDetectionTest,TestScroll)
+{
+  uint8_t* pSrc, *pRef;
+  int32_t iWidthSets[4] = {640,1024,1280,1980};
+  int32_t iHeightSets[4] = {360,768,720,1080};
+  int32_t iStride = 0;
+  int32_t iIdx = 0;
+
+  for(int32_t i=0; i<4; i++){
+    int32_t iWidth = iWidthSets[i];
+    int32_t iHeight = iHeightSets[i];
+    iStride = iWidth + 16;
+    pSrc = new uint8_t[iHeight*iStride];
+    ASSERT_TRUE(NULL != pSrc);
+    pRef = new uint8_t[iHeight*iStride];
+    ASSERT_MEMORY_FAIL2X(pSrc, pRef)
+    RandomPixelDataGenerator(pRef, iWidth, iHeight, iStride, iIdx );
+
+    int32_t iMvRange = iHeight/3;
+    int32_t iScrollMv = rand()%(iMvRange<<1) - iMvRange;
+    uint8_t* pSrcTmp = pSrc;
+    uint8_t* pRefTmp = pRef;
+
+    for (int32_t j=0;j<iHeight;j++) {
+      if ((j+iScrollMv)>=0 && (j+iScrollMv)<iHeight)
+        for (int32_t i=0;i<iWidth;i++) {
+            memcpy(pSrcTmp , &pRefTmp[(j+iScrollMv)*iStride], iWidth*sizeof(uint8_t));
+      } else {
+        for (int32_t i=0;i<iWidth;i++)
+          pSrcTmp[i] = rand()%256;
+      }
+      pSrcTmp += iStride;
+    }
+
+
+    SPixMap sSrcMap = { { 0 } };
+    SPixMap sRefMap = { { 0 } };
+
+    sSrcMap.pPixel[0] = pSrc;
+    sRefMap.pPixel[0] = pRef;
+    sSrcMap.iStride[0] = sRefMap.iStride[0] = iStride;
+    sSrcMap.sRect.iRectWidth = sRefMap.sRect.iRectWidth = iWidth;
+    sSrcMap.sRect.iRectHeight = sRefMap.sRect.iRectHeight = iHeight;
+
+    SScrollDetectionParam sScrollDetectionResult;
+    WelsMemset (&sScrollDetectionResult, 0, sizeof (sScrollDetectionResult));
+    int32_t iCoreNum = 1;
+    uint32_t uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
+
+    CScrollDetection *pTest =new CScrollDetection(uiCPUFlag);
+    int32_t iMethodIdx = METHOD_SCROLL_DETECTION;
+
+    pTest->Set(iMethodIdx, (&sScrollDetectionResult));
+    int32_t ret = pTest->Process(iMethodIdx,&sSrcMap, &sRefMap);
+    EXPECT_EQ(ret,0);
+    pTest->Get(iMethodIdx, (&sScrollDetectionResult));
+
+    EXPECT_EQ(sScrollDetectionResult.bScrollDetectFlag,1);
+    EXPECT_EQ(sScrollDetectionResult.iScrollMvY,iScrollMv);
+
+    delete pTest;
+    delete []pSrc;
+    delete []pRef;
+  }
+}
--- /dev/null
+++ b/test/processing/targets.mk
@@ -1,0 +1,10 @@
+PROCESSING_UNITTEST_SRCDIR=test/processing
+PROCESSING_UNITTEST_CPP_SRCS=\
+	$(PROCESSING_UNITTEST_SRCDIR)/ProcessUT_ScrollDetection.cpp\
+
+PROCESSING_UNITTEST_OBJS += $(PROCESSING_UNITTEST_CPP_SRCS:.cpp=.$(OBJ))
+
+OBJS += $(PROCESSING_UNITTEST_OBJS)
+$(PROCESSING_UNITTEST_SRCDIR)/%.$(OBJ): $(PROCESSING_UNITTEST_SRCDIR)/%.cpp
+	$(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(PROCESSING_UNITTEST_CFLAGS) $(PROCESSING_UNITTEST_INCLUDES) -c $(CXX_O) $<
+