updating vpm unit_test following r858

Review URL: http://webrtc-codereview.appspot.com/255005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@865 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mikhal@webrtc.org 2011-11-01 22:07:16 +00:00
parent 7395d3d8e9
commit bb8dfbdee2

View File

@ -14,7 +14,8 @@
using webrtc::Trace; using webrtc::Trace;
void TestSize(VideoFrame& sourceFrame, WebRtc_UWord32 targetWidth, WebRtc_UWord32 targetHeight, void TestSize(VideoFrame& sourceFrame,
WebRtc_UWord32 targetWidth, WebRtc_UWord32 targetHeight,
WebRtc_UWord32 mode, VideoProcessingModule *vpm); WebRtc_UWord32 mode, VideoProcessingModule *vpm);
class VPMEnvironment : public ::testing::Environment class VPMEnvironment : public ::testing::Environment
@ -56,14 +57,12 @@ void VideoProcessingModuleTest::SetUp()
void VideoProcessingModuleTest::TearDown() void VideoProcessingModuleTest::TearDown()
{ {
if (_sourceFile != NULL) if (_sourceFile != NULL) {
{
ASSERT_EQ(0, fclose(_sourceFile)); ASSERT_EQ(0, fclose(_sourceFile));
} }
_sourceFile = NULL; _sourceFile = NULL;
if (_vpm != NULL) if (_vpm != NULL) {
{
VideoProcessingModule::Destroy(_vpm); VideoProcessingModule::Destroy(_vpm);
} }
_vpm = NULL; _vpm = NULL;
@ -75,18 +74,22 @@ TEST_F(VideoProcessingModuleTest, GetVersionTest)
WebRtc_UWord32 remainingBuffer = sizeof(version); WebRtc_UWord32 remainingBuffer = sizeof(version);
WebRtc_UWord32 position = 0; WebRtc_UWord32 position = 0;
EXPECT_EQ(-1, VideoProcessingModule::GetVersion(NULL, remainingBuffer, position)); EXPECT_EQ(-1, VideoProcessingModule::GetVersion(NULL, remainingBuffer,
position));
EXPECT_EQ(-1, _vpm->GetVersion(NULL, remainingBuffer, position)); EXPECT_EQ(-1, _vpm->GetVersion(NULL, remainingBuffer, position));
WebRtc_UWord32 badRemainingBuffer = 5; WebRtc_UWord32 badRemainingBuffer = 5;
EXPECT_EQ(-3, VideoProcessingModule::GetVersion(version, badRemainingBuffer, position)); EXPECT_EQ(-3, VideoProcessingModule::GetVersion(version, badRemainingBuffer,
position));
EXPECT_EQ(-3, _vpm->GetVersion(version, badRemainingBuffer, position)); EXPECT_EQ(-3, _vpm->GetVersion(version, badRemainingBuffer, position));
EXPECT_EQ(0, VideoProcessingModule::GetVersion(version, remainingBuffer, position)); EXPECT_EQ(0, VideoProcessingModule::GetVersion(version, remainingBuffer,
position));
EXPECT_EQ(remainingBuffer, sizeof(version) - position); EXPECT_EQ(remainingBuffer, sizeof(version) - position);
printf("\n%s\n\n", version); printf("\n%s\n\n", version);
EXPECT_EQ(0, _vpm->GetVersion(&version[position], remainingBuffer, position)); EXPECT_EQ(0, _vpm->GetVersion(&version[position], remainingBuffer,
position));
EXPECT_EQ(remainingBuffer, sizeof(version) - position); EXPECT_EQ(remainingBuffer, sizeof(version) - position);
} }
@ -115,19 +118,21 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer)
EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats));
EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(NULL, NULL)); EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(NULL, NULL));
} }
TEST_F(VideoProcessingModuleTest, HandleBadStats) TEST_F(VideoProcessingModuleTest, HandleBadStats)
{ {
VideoProcessingModule::FrameStats stats; VideoProcessingModule::FrameStats stats;
ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile)); ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength,
_sourceFile));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), _width, _height, 0, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), _width, _height, 0,
stats));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), _width, _height, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), _width,
_height, stats));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats));
} }
@ -144,13 +149,15 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize)
EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame.Buffer(), 0, _height)); EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame.Buffer(), 0, _height));
EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame)); EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), 0, _height, 0, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), 0, _height, 0,
stats));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats));
EXPECT_EQ(-1, _vpm->Denoising(_videoFrame.Buffer(), 0, _height)); EXPECT_EQ(-1, _vpm->Denoising(_videoFrame.Buffer(), 0, _height));
EXPECT_EQ(-1, _vpm->Denoising(_videoFrame)); EXPECT_EQ(-1, _vpm->Denoising(_videoFrame));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), 0, _height, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), 0, _height,
stats));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats));
@ -163,21 +170,23 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize)
EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame.Buffer(), _width, 0)); EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame.Buffer(), _width, 0));
EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame)); EXPECT_EQ(-1, _vpm->ColorEnhancement(_videoFrame));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), _width, 0, 0, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame.Buffer(), _width, 0, 0,
stats));
EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats)); EXPECT_EQ(-1, _vpm->Deflickering(_videoFrame, stats));
EXPECT_EQ(-1, _vpm->Denoising(_videoFrame.Buffer(), _width, 0)); EXPECT_EQ(-1, _vpm->Denoising(_videoFrame.Buffer(), _width, 0));
EXPECT_EQ(-1, _vpm->Denoising(_videoFrame)); EXPECT_EQ(-1, _vpm->Denoising(_videoFrame));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), _width, 0, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame.Buffer(), _width, 0,
stats));
EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats));
EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0));
EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0));
VideoFrame *outFrame = NULL; VideoFrame *outFrame = NULL;
EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(&_videoFrame, &outFrame)); EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(&_videoFrame,
&outFrame));
} }
TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset)
@ -190,7 +199,8 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset)
videoFrame2.SetHeight(_height); videoFrame2.SetHeight(_height);
// Only testing non-static functions here. // Only testing non-static functions here.
ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile)); ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength,
_sourceFile));
ASSERT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame)); ASSERT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame));
memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength);
ASSERT_EQ(0, _vpm->Deflickering(_videoFrame, stats)); ASSERT_EQ(0, _vpm->Deflickering(_videoFrame, stats));
@ -198,36 +208,42 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset)
// Retrieve frame stats again in case Deflickering() has zeroed them. // Retrieve frame stats again in case Deflickering() has zeroed them.
ASSERT_EQ(0, _vpm->GetFrameStats(stats, videoFrame2)); ASSERT_EQ(0, _vpm->GetFrameStats(stats, videoFrame2));
ASSERT_EQ(0, _vpm->Deflickering(videoFrame2, stats)); ASSERT_EQ(0, _vpm->Deflickering(videoFrame2, stats));
EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), _frameLength)); EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(),
_frameLength));
ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile)); ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength,
_sourceFile));
memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength);
ASSERT_GE(_vpm->Denoising(_videoFrame), 0); ASSERT_GE(_vpm->Denoising(_videoFrame), 0);
_vpm->Reset(); _vpm->Reset();
ASSERT_GE(_vpm->Denoising(videoFrame2), 0); ASSERT_GE(_vpm->Denoising(videoFrame2), 0);
EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), _frameLength)); EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(),
_frameLength));
ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile)); ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength,
_sourceFile));
ASSERT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame)); ASSERT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame));
memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength);
ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats));
_vpm->Reset(); _vpm->Reset();
ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats));
EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), _frameLength)); EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(),
_frameLength));
} }
TEST_F(VideoProcessingModuleTest, FrameStats) TEST_F(VideoProcessingModuleTest, FrameStats)
{ {
VideoProcessingModule::FrameStats stats; VideoProcessingModule::FrameStats stats;
ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile)); ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength,
_sourceFile));
EXPECT_EQ(false, _vpm->ValidFrameStats(stats)); EXPECT_EQ(false, _vpm->ValidFrameStats(stats));
EXPECT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame)); EXPECT_EQ(0, _vpm->GetFrameStats(stats, _videoFrame));
EXPECT_EQ(true, _vpm->ValidFrameStats(stats)); EXPECT_EQ(true, _vpm->ValidFrameStats(stats));
printf("\nFrameStats\n"); printf("\nFrameStats\n");
printf("mean: %u\nnumPixels: %u\nsubSamplWidth: %u\nsumSamplHeight: %u\nsum: %u\n\n", printf("mean: %u\nnumPixels: %u\nsubSamplWidth: "
"%u\nsumSamplHeight: %u\nsum: %u\n\n",
static_cast<unsigned int>(stats.mean), static_cast<unsigned int>(stats.mean),
static_cast<unsigned int>(stats.numPixels), static_cast<unsigned int>(stats.numPixels),
static_cast<unsigned int>(stats.subSamplHeight), static_cast<unsigned int>(stats.subSamplHeight),
@ -240,21 +256,20 @@ TEST_F(VideoProcessingModuleTest, FrameStats)
TEST_F(VideoProcessingModuleTest, PreprocessorLogic) TEST_F(VideoProcessingModuleTest, PreprocessorLogic)
{ {
// disable temporal sampling // Disable temporal sampling
_vpm->EnableTemporalDecimation(false); _vpm->EnableTemporalDecimation(false);
ASSERT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); ASSERT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30));
ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 15)); ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 15));
//revert // Revert
_vpm->EnableTemporalDecimation(true); _vpm->EnableTemporalDecimation(true);
ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30));
// disable spatial sampling // Disable spatial sampling
_vpm->SetInputFrameResampleMode(kNoRescaling); _vpm->SetInputFrameResampleMode(kNoRescaling);
ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30));
VideoFrame *outFrame = NULL; VideoFrame *outFrame = NULL;
ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(&_videoFrame, &outFrame)); ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(&_videoFrame, &outFrame));
ASSERT_EQ(_videoFrame.Height() , outFrame->Height()); // No rescaling=> output frame = NULL
ASSERT_EQ(_videoFrame.Width() , outFrame->Width()); ASSERT_TRUE(outFrame == NULL);
} }
TEST_F(VideoProcessingModuleTest, Resampler) TEST_F(VideoProcessingModuleTest, Resampler)
@ -280,7 +295,7 @@ TEST_F(VideoProcessingModuleTest, Resampler)
// no temporal decimation // no temporal decimation
_vpm->EnableTemporalDecimation(false); _vpm->EnableTemporalDecimation(false);
// reading test frame // Reading test frame
VideoFrame sourceFrame; VideoFrame sourceFrame;
ASSERT_EQ(0, sourceFrame.VerifyAndAllocate(lengthSourceFrame)); ASSERT_EQ(0, sourceFrame.VerifyAndAllocate(lengthSourceFrame));
fread(sourceFrame.Buffer(), 1, lengthSourceFrame, _sourceFile); fread(sourceFrame.Buffer(), 1, lengthSourceFrame, _sourceFile);
@ -317,8 +332,7 @@ TEST_F(VideoProcessingModuleTest, Resampler)
t1 = TickTime::Now(); t1 = TickTime::Now();
accTicks += t1 - t0; accTicks += t1 - t0;
if (accTicks.Microseconds() < minRuntime || runIdx == 0) if (accTicks.Microseconds() < minRuntime || runIdx == 0) {
{
minRuntime = accTicks.Microseconds(); minRuntime = accTicks.Microseconds();
} }
avgRuntime += accTicks.Microseconds(); avgRuntime += accTicks.Microseconds();
@ -332,31 +346,34 @@ TEST_F(VideoProcessingModuleTest, Resampler)
printf("Min run time = %d us / frame\n\n", printf("Min run time = %d us / frame\n\n",
//static_cast<int>(minRuntime / frameNum)); //static_cast<int>(minRuntime / frameNum));
static_cast<int>(minRuntime)); static_cast<int>(minRuntime));
} }
void TestSize(VideoFrame& sourceFrame, WebRtc_UWord32 targetWidth, WebRtc_UWord32 targetHeight, void TestSize(VideoFrame& sourceFrame, WebRtc_UWord32 targetWidth,
WebRtc_UWord32 targetHeight,
WebRtc_UWord32 mode, VideoProcessingModule *vpm) WebRtc_UWord32 mode, VideoProcessingModule *vpm)
{ {
VideoFrame *outFrame = NULL; VideoFrame *outFrame = NULL;
std::ostringstream filename; std::ostringstream filename;
filename << "Resampler_"<< mode <<"_" << targetWidth << "x" << targetHeight << "_30Hz_P420.yuv"; filename << "Resampler_"<< mode <<"_" << targetWidth << "x" <<
std::cout << "Watch " << filename.str() << " and verify that it is okay." << std::endl; targetHeight << "_30Hz_P420.yuv";
std::cout << "Watch " << filename.str() << " and verify that it is okay."
<< std::endl;
FILE* standAloneFile = fopen(filename.str().c_str(), "wb"); FILE* standAloneFile = fopen(filename.str().c_str(), "wb");
ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetWidth, targetHeight, 30)); ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetWidth, targetHeight, 30));
ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(&sourceFrame, &outFrame)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(&sourceFrame, &outFrame));
// Length should be updated only if frame was resampled
if (targetWidth != sourceFrame.Width() ||
targetHeight != sourceFrame.Height()) {
ASSERT_EQ((targetWidth * targetHeight * 3 / 2), outFrame->Length()); ASSERT_EQ((targetWidth * targetHeight * 3 / 2), outFrame->Length());
// Write to file for visual inspection // Write to file for visual inspection
fwrite(outFrame->Buffer(), 1, outFrame->Length(), standAloneFile); fwrite(outFrame->Buffer(), 1, outFrame->Length(), standAloneFile);
outFrame->Free(); outFrame->Free();
}
fclose(standAloneFile); fclose(standAloneFile);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
VPMEnvironment* env = new VPMEnvironment; VPMEnvironment* env = new VPMEnvironment;
::testing::AddGlobalTestEnvironment(env); ::testing::AddGlobalTestEnvironment(env);