From 14b43beb7ce4440b30dcea31196de5b4a529cb6b Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Mon, 22 Oct 2012 18:19:23 +0000 Subject: Move src/ -> webrtc/ TBR=niklas.enbom@webrtc.org Review URL: https://webrtc-codereview.appspot.com/915006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2963 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 112 +++++++ .../main/test/unit_test/color_enhancement_test.cc | 119 +++++++ .../main/test/unit_test/content_metrics_test.cc | 40 +++ .../main/test/unit_test/createTable.m | 179 ++++++++++ .../main/test/unit_test/deflickering_test.cc | 94 ++++++ .../main/test/unit_test/denoising_test.cc | 133 ++++++++ .../main/test/unit_test/readYUV420file.m | 45 +++ .../main/test/unit_test/unit_test.cc | 372 +++++++++++++++++++++ .../main/test/unit_test/unit_test.h | 47 +++ .../main/test/unit_test/writeYUV420file.m | 22 ++ 10 files changed, 1163 insertions(+) create mode 100644 webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/createTable.m create mode 100644 webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/readYUV420file.m create mode 100644 webrtc/modules/video_processing/main/test/unit_test/unit_test.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/unit_test.h create mode 100644 webrtc/modules/video_processing/main/test/unit_test/writeYUV420file.m (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc new file mode 100644 index 0000000000..e8e688336b --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "unit_test.h" +#include "video_processing.h" + +using namespace webrtc; + +TEST_F(VideoProcessingModuleTest, BrightnessDetection) +{ + WebRtc_UWord32 frameNum = 0; + WebRtc_Word32 brightnessWarning = 0; + WebRtc_UWord32 warningCount = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == + _frameLength) + { + frameNum++; + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + stats), 0); + if (brightnessWarning != VideoProcessingModule::kNoWarning) + { + warningCount++; + } + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + // Expect few warnings + float warningProportion = static_cast(warningCount) / frameNum * 100; + printf("\nWarning proportions:\n"); + printf("Stock foreman: %.1f %%\n", warningProportion); + EXPECT_LT(warningProportion, 10); + + rewind(_sourceFile); + frameNum = 0; + warningCount = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == + _frameLength && + frameNum < 300) + { + frameNum++; + + WebRtc_UWord8* frame = _videoFrame.Buffer(); + WebRtc_UWord32 yTmp = 0; + for (WebRtc_UWord32 yIdx = 0; yIdx < _width * _height; yIdx++) + { + yTmp = frame[yIdx] << 1; + if (yTmp > 255) + { + yTmp = 255; + } + frame[yIdx] = static_cast(yTmp); + } + + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + stats), 0); + EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning); + if (brightnessWarning == VideoProcessingModule::kBrightWarning) + { + warningCount++; + } + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + // Expect many brightness warnings + warningProportion = static_cast(warningCount) / frameNum * 100; + printf("Bright foreman: %.1f %%\n", warningProportion); + EXPECT_GT(warningProportion, 95); + + rewind(_sourceFile); + frameNum = 0; + warningCount = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength && + frameNum < 300) + { + frameNum++; + + WebRtc_UWord8* frame = _videoFrame.Buffer(); + WebRtc_Word32 yTmp = 0; + for (WebRtc_UWord32 yIdx = 0; yIdx < _width * _height; yIdx++) + { + yTmp = frame[yIdx] >> 1; + frame[yIdx] = static_cast(yTmp); + } + + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + stats), 0); + EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning); + if (brightnessWarning == VideoProcessingModule::kDarkWarning) + { + warningCount++; + } + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + // Expect many darkness warnings + warningProportion = static_cast(warningCount) / frameNum * 100; + printf("Dark foreman: %.1f %%\n\n", warningProportion); + EXPECT_GT(warningProportion, 90); +} diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc new file mode 100644 index 0000000000..68bf43ecf3 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "common_video/libyuv/include/webrtc_libyuv.h" +#include "modules/video_processing/main/interface/video_processing.h" +#include "modules/video_processing/main/test/unit_test/unit_test.h" +#include "system_wrappers/interface/tick_util.h" +#include "testsupport/fileutils.h" + +namespace webrtc { + +TEST_F(VideoProcessingModuleTest, ColorEnhancement) +{ + TickTime t0; + TickTime t1; + TickInterval accTicks; + + // Use a shorter version of the Foreman clip for this test. + fclose(_sourceFile); + const std::string video_file = + webrtc::test::ResourcePath("foreman_cif_short", "yuv"); + _sourceFile = fopen(video_file.c_str(), "rb"); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read source file: " + video_file + "\n"; + + std::string output_file = webrtc::test::OutputPath() + + "foremanColorEnhancedVPM_cif_short.yuv"; + FILE* modFile = fopen(output_file.c_str(), "w+b"); + ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; + + WebRtc_UWord32 frameNum = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + { + frameNum++; + t0 = TickTime::Now(); + ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&_videoFrame)); + t1 = TickTime::Now(); + accTicks += t1 - t0; + if (fwrite(_videoFrame.Buffer(), 1, _frameLength, + modFile) != _frameLength) { + return; + } + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + printf("\nTime per frame: %d us \n", + static_cast(accTicks.Microseconds() / frameNum)); + rewind(modFile); + + printf("Comparing files...\n\n"); + std::string reference_filename = + webrtc::test::ResourcePath("foremanColorEnhanced_cif_short", "yuv"); + FILE* refFile = fopen(reference_filename.c_str(), "rb"); + ASSERT_TRUE(refFile != NULL) << "Cannot open reference file: " << + reference_filename << "\n" + "Create the reference by running Matlab script createTable.m."; + + // get file lenghts + ASSERT_EQ(0, fseek(refFile, 0L, SEEK_END)); + long refLen = ftell(refFile); + ASSERT_NE(-1L, refLen); + rewind(refFile); + ASSERT_EQ(0, fseek(modFile, 0L, SEEK_END)); + long testLen = ftell(modFile); + ASSERT_NE(-1L, testLen); + rewind(modFile); + ASSERT_EQ(refLen, testLen) << "File lengths differ."; + + VideoFrame refVideoFrame; + refVideoFrame.VerifyAndAllocate(_frameLength); + refVideoFrame.SetWidth(_width); + refVideoFrame.SetHeight(_height); + + // Compare frame-by-frame. + while (fread(_videoFrame.Buffer(), 1, _frameLength, modFile) == _frameLength) + { + ASSERT_EQ(_frameLength, fread(refVideoFrame.Buffer(), 1, _frameLength, refFile)); + EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), refVideoFrame.Buffer(), _frameLength)); + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + // Verify that all color pixels are enhanced, and no luminance values are + // altered. + + WebRtc_UWord8 *testFrame = new WebRtc_UWord8[_frameLength]; + + // Use value 128 as probe value, since we know that this will be changed + // in the enhancement. + memset(testFrame, 128, _frameLength); + + VideoFrame testVideoFrame; + testVideoFrame.CopyFrame(_frameLength, testFrame); + testVideoFrame.SetWidth(_width); + testVideoFrame.SetHeight(_height); + ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); + + EXPECT_EQ(0, memcmp(testVideoFrame.Buffer(), testFrame, _width * _height)) + << "Function is modifying the luminance."; + + EXPECT_NE(0, memcmp(testVideoFrame.Buffer() + _width * _height, + &testFrame[_width * _height], _width * _height / 2)) << + "Function is not modifying all chrominance pixels"; + + ASSERT_EQ(0, fclose(refFile)); + ASSERT_EQ(0, fclose(modFile)); + delete [] testFrame; +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc new file mode 100644 index 0000000000..0247e99546 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "modules/video_processing/main/interface/video_processing.h" +#include "modules/video_processing/main/source/content_analysis.h" +#include "modules/video_processing/main/test/unit_test/unit_test.h" + +namespace webrtc { + +TEST_F(VideoProcessingModuleTest, ContentAnalysis) +{ + VPMContentAnalysis _ca_c(false); + VPMContentAnalysis _ca_sse(true); + VideoContentMetrics *_cM_c, *_cM_SSE; + + _ca_c.Initialize(_width,_height); + _ca_sse.Initialize(_width,_height); + + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) + == _frameLength) + { + _cM_c = _ca_c.ComputeContentMetrics(_videoFrame); + _cM_SSE = _ca_sse.ComputeContentMetrics(_videoFrame); + + ASSERT_EQ(_cM_c->spatial_pred_err, _cM_SSE->spatial_pred_err); + ASSERT_EQ(_cM_c->spatial_pred_err_v, _cM_SSE->spatial_pred_err_v); + ASSERT_EQ(_cM_c->spatial_pred_err_h, _cM_SSE->spatial_pred_err_h); + ASSERT_EQ(_cM_c->motion_magnitude, _cM_SSE->motion_magnitude); + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/createTable.m b/webrtc/modules/video_processing/main/test/unit_test/createTable.m new file mode 100644 index 0000000000..2c7fb522f6 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/createTable.m @@ -0,0 +1,179 @@ +% Create the color enhancement look-up table and write it to +% file colorEnhancementTable.cpp. Copy contents of that file into +% the source file for the color enhancement function. + +clear +close all + + +% First, define the color enhancement in a normalized domain + +% Compander function is defined in three radial zones. +% 1. From 0 to radius r0, the compander function +% is a second-order polynomial intersecting the points (0,0) +% and (r0, r0), and with a slope B in (0,0). +% 2. From r0 to r1, the compander is a third-order polynomial +% intersecting the points (r0, r0) and (r1, r1), and with the +% same slope as the first part in the point (r0, r0) and slope +% equal to 1 in (r1, r1). +% 3. For radii larger than r1, the compander function is the +% unity scale function (no scaling at all). + +r0=0.07; % Dead zone radius (must be > 0) +r1=0.6; % Enhancement zone radius (must be > r0 and < 1) +B=0.2; % initial slope of compander function (between 0 and 1) + +x0=linspace(0,r0).'; % zone 1 +x1=linspace(r0,r1).'; % zone 2 +x2=linspace(r1,1).'; % zone 3 + +A=(1-B)/r0; +f0=A*x0.^2+B*x0; % compander function in zone 1 + +% equation system for finding second zone parameters +M=[r0^3 r0^2 r0 1; + 3*r0^2 2*r0 1 0; + 3*r1^2 2*r1 1 0; + r1^3 r1^2 r1 1]; +m=[A*r0^2+B*r0; 2*A*r0+B; 1; r1]; +% solve equations +theta=M\m; + +% compander function in zone 1 +f1=[x1.^3 x1.^2 x1 ones(size(x1))]*theta; + +x=[x0; x1; x2]; +f=[f0; f1; x2]; + +% plot it +figure(1) +plot(x,f,x,x,':') +xlabel('Normalized radius') +ylabel('Modified radius') + + +% Now, create the look-up table in the integer color space +[U,V]=meshgrid(0:255, 0:255); % U-V space +U0=U; +V0=V; + +% Conversion matrix from normalized YUV to RGB +T=[1 0 1.13983; 1 -0.39465 -0.58060; 1 2.03211 0]; +Ylum=0.5; + +figure(2) +Z(:,:,1)=Ylum + (U-127)/256*T(1,2) + (V-127)/256*T(1,3); +Z(:,:,2)=Ylum + (U-127)/256*T(2,2) + (V-127)/256*T(2,3); +Z(:,:,3)=Ylum + (U-127)/256*T(3,2) + (V-127)/256*T(3,3); +Z=max(Z,0); +Z=min(Z,1); +subplot(121) +image(Z); +axis square +axis off +set(gcf,'color','k') + +R = sqrt((U-127).^2 + (V-127).^2); +Rnorm = R/127; +RnormMod = Rnorm; +RnormMod(RnormMod==0)=1; % avoid division with zero + +% find indices to pixels in dead-zone (zone 1) +ix=find(Rnorm<=r0); +scaleMatrix = (A*Rnorm(ix).^2 + B*Rnorm(ix))./RnormMod(ix); +U(ix)=(U(ix)-127).*scaleMatrix+127; +V(ix)=(V(ix)-127).*scaleMatrix+127; + +% find indices to pixels in zone 2 +ix=find(Rnorm>r0 & Rnorm<=r1); +scaleMatrix = (theta(1)*Rnorm(ix).^3 + theta(2)*Rnorm(ix).^2 + ... + theta(3)*Rnorm(ix) + theta(4)) ./ RnormMod(ix); +U(ix)=(U(ix)-127).*scaleMatrix + 127; +V(ix)=(V(ix)-127).*scaleMatrix + 127; + +% round to integer values and saturate +U=round(U); +V=round(V); +U=max(min(U,255),0); +V=max(min(V,255),0); + +Z(:,:,1)=Ylum + (U-127)/256*T(1,2) + (V-127)/256*T(1,3); +Z(:,:,2)=Ylum + (U-127)/256*T(2,2) + (V-127)/256*T(2,3); +Z(:,:,3)=Ylum + (U-127)/256*T(3,2) + (V-127)/256*T(3,3); +Z=max(Z,0); +Z=min(Z,1); +subplot(122) +image(Z); +axis square +axis off + +figure(3) +subplot(121) +mesh(U-U0) +subplot(122) +mesh(V-V0) + + + +% Last, write to file +% Write only one matrix, since U=V' + +fid = fopen('../out/Debug/colorEnhancementTable.h','wt'); +if fid==-1 + error('Cannot open file colorEnhancementTable.cpp'); +end + +fprintf(fid,'//colorEnhancementTable.h\n\n'); +fprintf(fid,'//Copy the constant table to the appropriate header file.\n\n'); + +fprintf(fid,'//Table created with Matlab script createTable.m\n\n'); +fprintf(fid,'//Usage:\n'); +fprintf(fid,'// Umod=colorTable[U][V]\n'); +fprintf(fid,'// Vmod=colorTable[V][U]\n'); + +fprintf(fid,'static unsigned char colorTable[%i][%i] = {\n', size(U,1), size(U,2)); + +for u=1:size(U,2) + fprintf(fid,' {%i', U(1,u)); + for v=2:size(U,1) + fprintf(fid,', %i', U(v,u)); + end + fprintf(fid,'}'); + if u +#include + +#include "modules/video_processing/main/interface/video_processing.h" +#include "modules/video_processing/main/test/unit_test/unit_test.h" +#include "system_wrappers/interface/tick_util.h" +#include "testsupport/fileutils.h" + +namespace webrtc { + +TEST_F(VideoProcessingModuleTest, Deflickering) +{ + enum { NumRuns = 30 }; + WebRtc_UWord32 frameNum = 0; + const WebRtc_UWord32 frameRate = 15; + + WebRtc_Word64 minRuntime = 0; + WebRtc_Word64 avgRuntime = 0; + + // Close automatically opened Foreman. + fclose(_sourceFile); + const std::string input_file = + webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv"); + _sourceFile = fopen(input_file.c_str(), "rb"); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read input file: " << input_file << "\n"; + + const std::string output_file = + webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv"; + FILE* deflickerFile = fopen(output_file.c_str(), "wb"); + ASSERT_TRUE(deflickerFile != NULL) << + "Could not open output file: " << output_file << "\n"; + + printf("\nRun time [us / frame]:\n"); + for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + { + TickTime t0; + TickTime t1; + TickInterval accTicks; + WebRtc_UWord32 timeStamp = 1; + + frameNum = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + { + frameNum++; + _videoFrame.SetTimeStamp(timeStamp); + + t0 = TickTime::Now(); + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); + t1 = TickTime::Now(); + accTicks += t1 - t0; + + if (runIdx == 0) + { + if (fwrite(_videoFrame.Buffer(), 1, _frameLength, + deflickerFile) != _frameLength) { + return; + } + } + timeStamp += (90000 / frameRate); + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + printf("%u\n", static_cast(accTicks.Microseconds() / frameNum)); + if (accTicks.Microseconds() < minRuntime || runIdx == 0) + { + minRuntime = accTicks.Microseconds(); + } + avgRuntime += accTicks.Microseconds(); + + rewind(_sourceFile); + } + ASSERT_EQ(0, fclose(deflickerFile)); + // TODO(kjellander): Add verification of deflicker output file. + + printf("\nAverage run time = %d us / frame\n", + static_cast(avgRuntime / frameNum / NumRuns)); + printf("Min run time = %d us / frame\n\n", + static_cast(minRuntime / frameNum)); +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc new file mode 100644 index 0000000000..a4d97619b0 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "modules/video_processing/main/interface/video_processing.h" +#include "modules/video_processing/main/test/unit_test/unit_test.h" +#include "system_wrappers/interface/tick_util.h" +#include "testsupport/fileutils.h" + +namespace webrtc { + +TEST_F(VideoProcessingModuleTest, Denoising) +{ + enum { NumRuns = 10 }; + WebRtc_UWord32 frameNum = 0; + + WebRtc_Word64 minRuntime = 0; + WebRtc_Word64 avgRuntime = 0; + + const std::string denoise_filename = + webrtc::test::OutputPath() + "denoise_testfile.yuv"; + FILE* denoiseFile = fopen(denoise_filename.c_str(), "wb"); + ASSERT_TRUE(denoiseFile != NULL) << + "Could not open output file: " << denoise_filename << "\n"; + + const std::string noise_filename = + webrtc::test::OutputPath() + "noise_testfile.yuv"; + FILE* noiseFile = fopen(noise_filename.c_str(), "wb"); + ASSERT_TRUE(noiseFile != NULL) << + "Could not open noisy file: " << noise_filename << "\n"; + + printf("\nRun time [us / frame]:\n"); + for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + { + TickTime t0; + TickTime t1; + TickInterval accTicks; + WebRtc_Word32 modifiedPixels = 0; + + frameNum = 0; + while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + { + frameNum++; + WebRtc_UWord8* sourceBuffer = _videoFrame.Buffer(); + + // Add noise to a part in video stream + // Random noise + // TODO: investigate the effectiveness of this test. + + //for(WebRtc_UWord32 ir = 0; ir < _frameLength; ir++) + // sourceBuffer[ir] = 128 + for (WebRtc_UWord32 ir = 0; ir < _height; ir++) + { + WebRtc_UWord32 ik = ir * _width; + for (WebRtc_UWord32 ic = 0; ic < _width; ic++) + { + WebRtc_UWord8 r = rand() % 16; + r -= 8; + if (ir < _height / 4) + r = 0; + if (ir >= 3 * _height / 4) + r = 0; + if (ic < _width / 4) + r = 0; + if (ic >= 3 * _width / 4) + r = 0; + + /*WebRtc_UWord8 pixelValue = 0; + if (ir >= _height / 2) + { // Region 3 or 4 + pixelValue = 170; + } + if (ic >= _width / 2) + { // Region 2 or 4 + pixelValue += 85; + } + pixelValue += r; + sourceBuffer[ik + ic] = pixelValue; + */ + sourceBuffer[ik + ic] += r; + } + } + + if (runIdx == 0) + { + if (fwrite(_videoFrame.Buffer(), 1, _frameLength, + noiseFile) != _frameLength) { + return; + } + } + + t0 = TickTime::Now(); + ASSERT_GE(modifiedPixels = _vpm->Denoising(&_videoFrame), 0); + t1 = TickTime::Now(); + accTicks += t1 - t0; + + if (runIdx == 0) + { + if (fwrite(_videoFrame.Buffer(), 1, _frameLength, + denoiseFile) != _frameLength) { + return; + } + } + } + ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + + printf("%u\n", static_cast(accTicks.Microseconds() / frameNum)); + if (accTicks.Microseconds() < minRuntime || runIdx == 0) + { + minRuntime = accTicks.Microseconds(); + } + avgRuntime += accTicks.Microseconds(); + + rewind(_sourceFile); + } + ASSERT_EQ(0, fclose(denoiseFile)); + ASSERT_EQ(0, fclose(noiseFile)); + printf("\nAverage run time = %d us / frame\n", + static_cast(avgRuntime / frameNum / NumRuns)); + printf("Min run time = %d us / frame\n\n", + static_cast(minRuntime / frameNum)); +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/readYUV420file.m b/webrtc/modules/video_processing/main/test/unit_test/readYUV420file.m new file mode 100644 index 0000000000..03013efd3a --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/readYUV420file.m @@ -0,0 +1,45 @@ +function [Y,U,V] = readYUV420file(filename, width, height) +% [Y,U,V] = readYUVfile(filename, width, height) + +fid = fopen(filename,'rb'); +if fid==-1 + error(['Cannot open file ' filename]); +end + +% Number of pixels per image +nPx=width*height; + +% nPx bytes luminance, nPx/4 bytes U, nPx/4 bytes V +frameSizeBytes = nPx*1.5; + +% calculate number of frames +fseek(fid,0,'eof'); % move to end of file +fileLen=ftell(fid); % number of bytes +fseek(fid,0,'bof'); % rewind to start + +% calculate number of frames +numFrames = floor(fileLen/frameSizeBytes); + +Y=uint8(zeros(height,width,numFrames)); +U=uint8(zeros(height/2,width/2,numFrames)); +V=uint8(zeros(height/2,width/2,numFrames)); + +[X,nBytes]=fread(fid, frameSizeBytes, 'uchar'); + +for k=1:numFrames + + % Store luminance + Y(:,:,k)=uint8(reshape(X(1:nPx), width, height).'); + + % Store U channel + U(:,:,k)=uint8(reshape(X(nPx + (1:nPx/4)), width/2, height/2).'); + + % Store V channel + V(:,:,k)=uint8(reshape(X(nPx + nPx/4 + (1:nPx/4)), width/2, height/2).'); + + % Read next frame + [X,nBytes]=fread(fid, frameSizeBytes, 'uchar'); +end + + +fclose(fid); diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc new file mode 100644 index 0000000000..f6d7d10b13 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "modules/video_processing/main/test/unit_test/unit_test.h" + +#include + +#include "common_video/libyuv/include/webrtc_libyuv.h" +#include "system_wrappers/interface/tick_util.h" +#include "testsupport/fileutils.h" + +namespace webrtc { + +// The |sourceFrame| is scaled to |target_width|,|target_height|, using the +// filter mode set to |mode|. The |expected_psnr| is used to verify basic +// quality when the resampled frame is scaled back up/down to the +// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than +// actual PSNR verified under the same conditions. +void TestSize(const VideoFrame& sourceFrame, int target_width, + int target_height, int mode, double expected_psnr, + VideoProcessingModule* vpm); + +VideoProcessingModuleTest::VideoProcessingModuleTest() : + _vpm(NULL), + _sourceFile(NULL), + _width(352), + _height(288), + _frameLength(CalcBufferSize(kI420, 352, 288)) +{ +} + +void VideoProcessingModuleTest::SetUp() +{ + _vpm = VideoProcessingModule::Create(0); + ASSERT_TRUE(_vpm != NULL); + + ASSERT_EQ(0, _videoFrame.VerifyAndAllocate(_frameLength)); + _videoFrame.SetWidth(_width); + _videoFrame.SetHeight(_height); + + const std::string video_file = + webrtc::test::ResourcePath("foreman_cif", "yuv"); + _sourceFile = fopen(video_file.c_str(),"rb"); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read source file: " + video_file + "\n"; +} + +void VideoProcessingModuleTest::TearDown() +{ + if (_sourceFile != NULL) { + ASSERT_EQ(0, fclose(_sourceFile)); + } + _sourceFile = NULL; + + if (_vpm != NULL) { + VideoProcessingModule::Destroy(_vpm); + } + _vpm = NULL; +} + +TEST_F(VideoProcessingModuleTest, HandleNullBuffer) +{ + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + // Video frame with unallocated buffer. + VideoFrame videoFrame; + videoFrame.SetWidth(_width); + videoFrame.SetHeight(_height); + + EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, videoFrame)); + + EXPECT_EQ(-1, _vpm->ColorEnhancement(&videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&videoFrame, &stats)); + + EXPECT_EQ(-1, _vpm->Denoising(&videoFrame)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats)); +} + +TEST_F(VideoProcessingModuleTest, HandleBadStats) +{ + VideoProcessingModule::FrameStats stats; + + ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + _sourceFile)); + + _videoFrame.SetWidth(_width); + _videoFrame.SetHeight(_height); + EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); +} + +TEST_F(VideoProcessingModuleTest, HandleBadSize) +{ + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + + // Bad width + _videoFrame.SetWidth(0); + EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); + + EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + + EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); + + // Bad height + _videoFrame.SetWidth(_width); + _videoFrame.SetHeight(0); + EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); + + EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + + EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); + + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); + + VideoFrame *outFrame = NULL; + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(_videoFrame, + &outFrame)); +} + +TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) +{ + VideoFrame videoFrame2; + VideoProcessingModule::FrameStats stats; + + ASSERT_EQ(0, videoFrame2.VerifyAndAllocate(_frameLength)); + videoFrame2.SetWidth(_width); + videoFrame2.SetHeight(_height); + + // Only testing non-static functions here. + ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + _sourceFile)); + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); + _vpm->Reset(); + // Retrieve frame stats again in case Deflickering() has zeroed them. + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, videoFrame2)); + ASSERT_EQ(0, _vpm->Deflickering(&videoFrame2, &stats)); + EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), + _frameLength)); + + ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + _sourceFile)); + memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); + _vpm->Reset(); + ASSERT_GE(_vpm->Denoising(&videoFrame2), 0); + EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), + _frameLength)); + + ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + _sourceFile)); + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); + _vpm->Reset(); + ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); + EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), + _frameLength)); +} + +TEST_F(VideoProcessingModuleTest, FrameStats) +{ + VideoProcessingModule::FrameStats stats; + ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + _sourceFile)); + + EXPECT_FALSE(_vpm->ValidFrameStats(stats)); + EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + EXPECT_TRUE(_vpm->ValidFrameStats(stats)); + + printf("\nFrameStats\n"); + printf("mean: %u\nnumPixels: %u\nsubSamplWidth: " + "%u\nsumSamplHeight: %u\nsum: %u\n\n", + static_cast(stats.mean), + static_cast(stats.numPixels), + static_cast(stats.subSamplHeight), + static_cast(stats.subSamplWidth), + static_cast(stats.sum)); + + _vpm->ClearFrameStats(&stats); + EXPECT_FALSE(_vpm->ValidFrameStats(stats)); +} + +TEST_F(VideoProcessingModuleTest, PreprocessorLogic) +{ + // Disable temporal sampling + _vpm->EnableTemporalDecimation(false); + ASSERT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); + ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 15)); + // Revert + _vpm->EnableTemporalDecimation(true); + ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); + // Disable spatial sampling + _vpm->SetInputFrameResampleMode(kNoRescaling); + ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); + VideoFrame *outFrame = NULL; + ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + // No rescaling=> output frame = NULL + ASSERT_TRUE(outFrame == NULL); +} + +TEST_F(VideoProcessingModuleTest, Resampler) +{ + enum { NumRuns = 1 }; + + WebRtc_Word64 minRuntime = 0; + WebRtc_Word64 avgRuntime = 0; + + TickTime t0; + TickTime t1; + TickInterval accTicks; + WebRtc_Word32 height = 288; + WebRtc_Word32 width = 352; + WebRtc_Word32 lengthSourceFrame = width*height*3/2; + + rewind(_sourceFile); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read input file \n"; + + // CA not needed here + _vpm->EnableContentAnalysis(false); + // no temporal decimation + _vpm->EnableTemporalDecimation(false); + + // Reading test frame + VideoFrame sourceFrame; + ASSERT_EQ(0, sourceFrame.VerifyAndAllocate(lengthSourceFrame)); + EXPECT_GT(fread(sourceFrame.Buffer(), 1, lengthSourceFrame, _sourceFile), 0u); + ASSERT_EQ(0, sourceFrame.SetLength(lengthSourceFrame)); + sourceFrame.SetHeight(height); + sourceFrame.SetWidth(width); + + for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + { + // initiate test timer + t0 = TickTime::Now(); + + // Test scaling to different sizes: source is of |width|/|height| = 352/288. + // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). + TestSize(sourceFrame, 100, 50, 3, 24.0, _vpm); + TestSize(sourceFrame, 352/4, 288/4, 3, 25.2, _vpm); + TestSize(sourceFrame, 352/2, 288/2, 3, 28.1, _vpm); + TestSize(sourceFrame, 352, 288, 3, -1, _vpm); // no resampling. + TestSize(sourceFrame, 2*352, 2*288, 3, 32.2, _vpm); + TestSize(sourceFrame, 400, 256, 3, 31.3, _vpm); + TestSize(sourceFrame, 480, 640, 3, 32.15, _vpm); + TestSize(sourceFrame, 960, 720, 3, 32.2, _vpm); + TestSize(sourceFrame, 1280, 720, 3, 32.15, _vpm); + // Upsampling to odd size. + TestSize(sourceFrame, 501, 333, 3, 32.05, _vpm); + // Downsample to odd size. + TestSize(sourceFrame, 281, 175, 3, 29.3, _vpm); + + // stop timer + t1 = TickTime::Now(); + accTicks += t1 - t0; + + if (accTicks.Microseconds() < minRuntime || runIdx == 0) { + minRuntime = accTicks.Microseconds(); + } + avgRuntime += accTicks.Microseconds(); + } + + sourceFrame.Free(); + + printf("\nAverage run time = %d us / frame\n", + //static_cast(avgRuntime / frameNum / NumRuns)); + static_cast(avgRuntime)); + printf("Min run time = %d us / frame\n\n", + //static_cast(minRuntime / frameNum)); + static_cast(minRuntime)); +} + +void TestSize(const VideoFrame& source_frame, int target_width, + int target_height, int mode, double expected_psnr, + VideoProcessingModule* vpm) { + int source_width = source_frame.Width(); + int source_height = source_frame.Height(); + VideoFrame* out_frame = NULL; + + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); + + // If the frame was resampled (scale changed) then: + // (1) verify the new size and write out processed frame for viewing. + // (2) scale the resampled frame (|out_frame|) back to the original size and + // compute PSNR relative to |source_frame| (for automatic verification). + // (3) write out the processed frame for viewing. + if (target_width != static_cast(source_width) || + target_height != static_cast(source_height)) { + int target_half_width = (target_width + 1) >> 1; + int target_half_height = (target_height + 1) >> 1; + int required_size_resampled = target_width * target_height + + 2 * (target_half_width * target_half_height); + ASSERT_EQ(required_size_resampled, static_cast(out_frame->Length())); + + // Write the processed frame to file for visual inspection. + std::ostringstream filename; + filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << source_width << "x" << source_height << "_to_" << + target_width << "x" << target_height << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename.str() << " and verify that it is okay." + << std::endl; + FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); + if (fwrite(out_frame->Buffer(), 1, + out_frame->Length(), stand_alone_file) != out_frame->Length()) { + fprintf(stderr, "Failed to write frame for scaling to width/height: " + " %d %d \n", target_width, target_height); + return; + } + fclose(stand_alone_file); + + VideoFrame resampled_source_frame; + resampled_source_frame.CopyFrame(*out_frame); + + // Scale |resampled_source_frame| back to original/source size. + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(source_width, + source_height, + 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, + &out_frame)); + + // Write the processed frame to file for visual inspection. + std::ostringstream filename2; + filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << target_width << "x" << target_height << "_to_" << + source_width << "x" << source_height << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename2.str() << " and verify that it is okay." + << std::endl; + stand_alone_file = fopen(filename2.str().c_str(), "wb"); + if (fwrite(out_frame->Buffer(), 1, + out_frame->Length(), stand_alone_file) != out_frame->Length()) { + fprintf(stderr, "Failed to write frame for scaling to width/height " + "%d %d \n", source_width, source_height); + return; + } + fclose(stand_alone_file); + + // Compute the PSNR and check expectation. + double psnr = I420PSNR(source_frame.Buffer(), out_frame->Buffer(), + source_width, source_height); + EXPECT_GT(psnr, expected_psnr); + printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " + "source which is scaled down/up to: %d %d, and back to source size \n", + psnr, source_width, source_height, target_width, target_height); + + resampled_source_frame.Free(); + } +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h new file mode 100644 index 0000000000..2363e1a146 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H +#define WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H + +#include "gtest/gtest.h" +#include "modules/video_processing/main/interface/video_processing.h" +#include "system_wrappers/interface/trace.h" +#include "testsupport/fileutils.h" + +namespace webrtc { + +class VideoProcessingModuleTest : public ::testing::Test +{ +protected: + VideoProcessingModuleTest(); + virtual void SetUp(); + virtual void TearDown(); + static void SetUpTestCase() + { + Trace::CreateTrace(); + std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt"; + ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str())); + } + static void TearDownTestCase() + { + Trace::ReturnTrace(); + } + VideoProcessingModule* _vpm; + FILE* _sourceFile; + VideoFrame _videoFrame; + const WebRtc_UWord32 _width; + const WebRtc_UWord32 _height; + const WebRtc_UWord32 _frameLength; +}; + +} // namespace webrtc + +#endif // WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H diff --git a/webrtc/modules/video_processing/main/test/unit_test/writeYUV420file.m b/webrtc/modules/video_processing/main/test/unit_test/writeYUV420file.m new file mode 100644 index 0000000000..69a8808338 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/writeYUV420file.m @@ -0,0 +1,22 @@ +function writeYUV420file(filename, Y, U, V) +% writeYUV420file(filename, Y, U, V) + +fid = fopen(filename,'wb'); +if fid==-1 + error(['Cannot open file ' filename]); +end + +numFrames=size(Y,3); + +for k=1:numFrames + % Write luminance + fwrite(fid,uint8(Y(:,:,k).'), 'uchar'); + + % Write U channel + fwrite(fid,uint8(U(:,:,k).'), 'uchar'); + + % Write V channel + fwrite(fid,uint8(V(:,:,k).'), 'uchar'); +end + +fclose(fid); -- cgit v1.2.3 From 9fedff7c17a8d3dc46ed5b3207220f59a22391d6 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Wed, 24 Oct 2012 18:33:04 +0000 Subject: Switching to I420VideoFrame Review URL: https://webrtc-codereview.appspot.com/922004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2983 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 43 +++-- .../main/test/unit_test/color_enhancement_test.cc | 75 ++++++--- .../main/test/unit_test/content_metrics_test.cc | 11 +- .../main/test/unit_test/deflickering_test.cc | 16 +- .../main/test/unit_test/denoising_test.cc | 25 +-- .../main/test/unit_test/unit_test.cc | 181 +++++++++++---------- .../main/test/unit_test/unit_test.h | 11 +- 7 files changed, 225 insertions(+), 137 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index e8e688336b..ffb1c41eae 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -18,9 +18,16 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) WebRtc_UWord32 frameNum = 0; WebRtc_Word32 brightnessWarning = 0; WebRtc_UWord32 warningCount = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == - _frameLength) + scoped_array video_buffer(new uint8_t[_frame_length]); + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); frameNum++; VideoProcessingModule::FrameStats stats; ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); @@ -42,15 +49,21 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) rewind(_sourceFile); frameNum = 0; warningCount = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == - _frameLength && + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length && frameNum < 300) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); frameNum++; - WebRtc_UWord8* frame = _videoFrame.Buffer(); + WebRtc_UWord8* frame = _videoFrame.buffer(kYPlane); WebRtc_UWord32 yTmp = 0; - for (WebRtc_UWord32 yIdx = 0; yIdx < _width * _height; yIdx++) + for (int yIdx = 0; yIdx < _width * _height; yIdx++) { yTmp = frame[yIdx] << 1; if (yTmp > 255) @@ -80,17 +93,23 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) rewind(_sourceFile); frameNum = 0; warningCount = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength && - frameNum < 300) + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length && frameNum < 300) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); frameNum++; - WebRtc_UWord8* frame = _videoFrame.Buffer(); + WebRtc_UWord8* y_plane = _videoFrame.buffer(kYPlane); WebRtc_Word32 yTmp = 0; - for (WebRtc_UWord32 yIdx = 0; yIdx < _width * _height; yIdx++) + for (int yIdx = 0; yIdx < _width * _height; yIdx++) { - yTmp = frame[yIdx] >> 1; - frame[yIdx] = static_cast(yTmp); + yTmp = y_plane[yIdx] >> 1; + y_plane[yIdx] = static_cast(yTmp); } VideoProcessingModule::FrameStats stats; diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index 68bf43ecf3..85029fea40 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -39,15 +39,22 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; WebRtc_UWord32 frameNum = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + scoped_array video_buffer(new uint8_t[_frame_length]); + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); frameNum++; t0 = TickTime::Now(); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&_videoFrame)); t1 = TickTime::Now(); accTicks += t1 - t0; - if (fwrite(_videoFrame.Buffer(), 1, _frameLength, - modFile) != _frameLength) { + if (PrintI420VideoFrame(_videoFrame, modFile) < 0) { return; } } @@ -76,44 +83,70 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) rewind(modFile); ASSERT_EQ(refLen, testLen) << "File lengths differ."; - VideoFrame refVideoFrame; - refVideoFrame.VerifyAndAllocate(_frameLength); - refVideoFrame.SetWidth(_width); - refVideoFrame.SetHeight(_height); + I420VideoFrame refVideoFrame; // Compare frame-by-frame. - while (fread(_videoFrame.Buffer(), 1, _frameLength, modFile) == _frameLength) + scoped_array ref_buffer(new uint8_t[_frame_length]); + while (fread(video_buffer.get(), 1, _frame_length, modFile) == + _frame_length) { - ASSERT_EQ(_frameLength, fread(refVideoFrame.Buffer(), 1, _frameLength, refFile)); - EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), refVideoFrame.Buffer(), _frameLength)); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); + ASSERT_EQ(_frame_length, fread(ref_buffer.get(), 1, _frame_length, + refFile)); + refVideoFrame.CreateFrame(_size_y, ref_buffer.get(), + _size_uv, ref_buffer.get() + _size_y, + _size_uv, ref_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); + EXPECT_EQ(0, memcmp(_videoFrame.buffer(kYPlane), + refVideoFrame.buffer(kYPlane), + _size_y)); + EXPECT_EQ(0, memcmp(_videoFrame.buffer(kUPlane), + refVideoFrame.buffer(kUPlane), + _size_uv)); + EXPECT_EQ(0, memcmp(_videoFrame.buffer(kVPlane), + refVideoFrame.buffer(kVPlane), + _size_uv)); } ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; // Verify that all color pixels are enhanced, and no luminance values are // altered. - WebRtc_UWord8 *testFrame = new WebRtc_UWord8[_frameLength]; + scoped_array testFrame(new WebRtc_UWord8[_frame_length]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. - memset(testFrame, 128, _frameLength); + memset(testFrame.get(), 128, _frame_length); + + I420VideoFrame testVideoFrame; + testVideoFrame.CreateFrame(_size_y, testFrame.get(), + _size_uv, testFrame.get() + _size_y, + _size_uv, testFrame.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); - VideoFrame testVideoFrame; - testVideoFrame.CopyFrame(_frameLength, testFrame); - testVideoFrame.SetWidth(_width); - testVideoFrame.SetHeight(_height); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); - EXPECT_EQ(0, memcmp(testVideoFrame.Buffer(), testFrame, _width * _height)) + EXPECT_EQ(0, memcmp(testVideoFrame.buffer(kYPlane), testFrame.get(), + _size_y)) << "Function is modifying the luminance."; - EXPECT_NE(0, memcmp(testVideoFrame.Buffer() + _width * _height, - &testFrame[_width * _height], _width * _height / 2)) << - "Function is not modifying all chrominance pixels"; + EXPECT_NE(0, memcmp(testVideoFrame.buffer(kUPlane), + testFrame.get() + _size_y, _size_uv)) << + "Function is not modifying all chrominance pixels"; + EXPECT_NE(0, memcmp(testVideoFrame.buffer(kVPlane), + testFrame.get() + _size_y + _size_uv, _size_uv)) << + "Function is not modifying all chrominance pixels"; ASSERT_EQ(0, fclose(refFile)); ASSERT_EQ(0, fclose(modFile)); - delete [] testFrame; } } // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 0247e99546..cf784c74ea 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -23,9 +23,16 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) _ca_c.Initialize(_width,_height); _ca_sse.Initialize(_width,_height); - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) - == _frameLength) + scoped_array video_buffer(new uint8_t[_frame_length]); + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) + == _frame_length) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); _cM_c = _ca_c.ComputeContentMetrics(_videoFrame); _cM_SSE = _ca_sse.ComputeContentMetrics(_videoFrame); diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 7119bdb87d..bf284fcb61 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -11,6 +11,7 @@ #include #include +#include "common_video/libyuv/include/webrtc_libyuv.h" #include "modules/video_processing/main/interface/video_processing.h" #include "modules/video_processing/main/test/unit_test/unit_test.h" #include "system_wrappers/interface/tick_util.h" @@ -42,6 +43,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) "Could not open output file: " << output_file << "\n"; printf("\nRun time [us / frame]:\n"); + scoped_array video_buffer(new uint8_t[_frame_length]); for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) { TickTime t0; @@ -50,10 +52,17 @@ TEST_F(VideoProcessingModuleTest, Deflickering) WebRtc_UWord32 timeStamp = 1; frameNum = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length) { frameNum++; - _videoFrame.SetTimeStamp(timeStamp); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + + _size_uv, + _width, _height, + _width, _half_width, _half_width); + _videoFrame.set_timestamp(timeStamp); t0 = TickTime::Now(); VideoProcessingModule::FrameStats stats; @@ -64,8 +73,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) if (runIdx == 0) { - if (fwrite(_videoFrame.Buffer(), 1, _frameLength, - deflickerFile) != _frameLength) { + if (PrintI420VideoFrame(_videoFrame, deflickerFile) < 0) { return; } } diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index a4d97619b0..1d0f9a28db 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -11,6 +11,7 @@ #include #include +#include "common_video/libyuv/include/webrtc_libyuv.h" #include "modules/video_processing/main/interface/video_processing.h" #include "modules/video_processing/main/test/unit_test/unit_test.h" #include "system_wrappers/interface/tick_util.h" @@ -47,21 +48,27 @@ TEST_F(VideoProcessingModuleTest, Denoising) WebRtc_Word32 modifiedPixels = 0; frameNum = 0; - while (fread(_videoFrame.Buffer(), 1, _frameLength, _sourceFile) == _frameLength) + scoped_array video_buffer(new uint8_t[_frame_length]); + while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == + _frame_length) { + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, + video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); frameNum++; - WebRtc_UWord8* sourceBuffer = _videoFrame.Buffer(); + WebRtc_UWord8* sourceBuffer = _videoFrame.buffer(kYPlane); // Add noise to a part in video stream // Random noise // TODO: investigate the effectiveness of this test. - //for(WebRtc_UWord32 ir = 0; ir < _frameLength; ir++) - // sourceBuffer[ir] = 128 - for (WebRtc_UWord32 ir = 0; ir < _height; ir++) + for (int ir = 0; ir < _height; ir++) { WebRtc_UWord32 ik = ir * _width; - for (WebRtc_UWord32 ic = 0; ic < _width; ic++) + for (int ic = 0; ic < _width; ic++) { WebRtc_UWord8 r = rand() % 16; r -= 8; @@ -92,8 +99,7 @@ TEST_F(VideoProcessingModuleTest, Denoising) if (runIdx == 0) { - if (fwrite(_videoFrame.Buffer(), 1, _frameLength, - noiseFile) != _frameLength) { + if (PrintI420VideoFrame(_videoFrame, noiseFile) < 0) { return; } } @@ -105,8 +111,7 @@ TEST_F(VideoProcessingModuleTest, Denoising) if (runIdx == 0) { - if (fwrite(_videoFrame.Buffer(), 1, _frameLength, - denoiseFile) != _frameLength) { + if (PrintI420VideoFrame(_videoFrame, noiseFile) < 0) { return; } } diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index f6d7d10b13..2b06ccd6ea 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -23,16 +23,21 @@ namespace webrtc { // quality when the resampled frame is scaled back up/down to the // original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than // actual PSNR verified under the same conditions. -void TestSize(const VideoFrame& sourceFrame, int target_width, +void TestSize(const I420VideoFrame& sourceFrame, int target_width, int target_height, int mode, double expected_psnr, VideoProcessingModule* vpm); +bool CompareFrames(const webrtc::I420VideoFrame& frame1, + const webrtc::I420VideoFrame& frame2); VideoProcessingModuleTest::VideoProcessingModuleTest() : _vpm(NULL), _sourceFile(NULL), _width(352), + _half_width(_width / 2), _height(288), - _frameLength(CalcBufferSize(kI420, 352, 288)) + _size_y(_width * _height), + _size_uv(_half_width * _height /2), + _frame_length(CalcBufferSize(kI420, _width, _height)) { } @@ -41,9 +46,8 @@ void VideoProcessingModuleTest::SetUp() _vpm = VideoProcessingModule::Create(0); ASSERT_TRUE(_vpm != NULL); - ASSERT_EQ(0, _videoFrame.VerifyAndAllocate(_frameLength)); - _videoFrame.SetWidth(_width); - _videoFrame.SetHeight(_height); + ASSERT_EQ(0, _videoFrame.CreateEmptyFrame(_width, _height, _width, + _half_width, _half_width)); const std::string video_file = webrtc::test::ResourcePath("foreman_cif", "yuv"); @@ -70,9 +74,9 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) VideoProcessingModule::FrameStats stats; ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); // Video frame with unallocated buffer. - VideoFrame videoFrame; - videoFrame.SetWidth(_width); - videoFrame.SetHeight(_height); + I420VideoFrame videoFrame; + videoFrame.set_width(_width); + videoFrame.set_height(_height); EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, videoFrame)); @@ -88,12 +92,15 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) TEST_F(VideoProcessingModuleTest, HandleBadStats) { VideoProcessingModule::FrameStats stats; + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); - ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, - _sourceFile)); - - _videoFrame.SetWidth(_width); - _videoFrame.SetHeight(_height); EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); @@ -104,21 +111,9 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) VideoProcessingModule::FrameStats stats; ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - // Bad width - _videoFrame.SetWidth(0); - EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); - - EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); - - EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); - - EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); - - EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); - - // Bad height - _videoFrame.SetWidth(_width); - _videoFrame.SetHeight(0); + _videoFrame.ResetSize(); + _videoFrame.set_width(_width); + _videoFrame.set_height(0); EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); @@ -132,58 +127,73 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); - VideoFrame *outFrame = NULL; + I420VideoFrame *outFrame = NULL; EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(_videoFrame, &outFrame)); } TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { - VideoFrame videoFrame2; + I420VideoFrame videoFrame2; VideoProcessingModule::FrameStats stats; - - ASSERT_EQ(0, videoFrame2.VerifyAndAllocate(_frameLength)); - videoFrame2.SetWidth(_width); - videoFrame2.SetHeight(_height); - // Only testing non-static functions here. - ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); + ASSERT_EQ(0, _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width)); ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + ASSERT_EQ(0, videoFrame2.CopyFrame(_videoFrame)); ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); _vpm->Reset(); // Retrieve frame stats again in case Deflickering() has zeroed them. ASSERT_EQ(0, _vpm->GetFrameStats(&stats, videoFrame2)); ASSERT_EQ(0, _vpm->Deflickering(&videoFrame2, &stats)); - EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), - _frameLength)); - - ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, - _sourceFile)); - memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); + videoFrame2.CopyFrame(_videoFrame); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); _vpm->Reset(); ASSERT_GE(_vpm->Denoising(&videoFrame2), 0); - EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), - _frameLength)); - - ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, - _sourceFile)); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - memcpy(videoFrame2.Buffer(), _videoFrame.Buffer(), _frameLength); + videoFrame2.CopyFrame(_videoFrame); ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); _vpm->Reset(); ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); - EXPECT_EQ(0, memcmp(_videoFrame.Buffer(), videoFrame2.Buffer(), - _frameLength)); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); } TEST_F(VideoProcessingModuleTest, FrameStats) { VideoProcessingModule::FrameStats stats; - ASSERT_EQ(_frameLength, fread(_videoFrame.Buffer(), 1, _frameLength, - _sourceFile)); + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + _videoFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); EXPECT_FALSE(_vpm->ValidFrameStats(stats)); EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); @@ -214,7 +224,7 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) // Disable spatial sampling _vpm->SetInputFrameResampleMode(kNoRescaling); ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); - VideoFrame *outFrame = NULL; + I420VideoFrame *outFrame = NULL; ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); // No rescaling=> output frame = NULL ASSERT_TRUE(outFrame == NULL); @@ -230,9 +240,6 @@ TEST_F(VideoProcessingModuleTest, Resampler) TickTime t0; TickTime t1; TickInterval accTicks; - WebRtc_Word32 height = 288; - WebRtc_Word32 width = 352; - WebRtc_Word32 lengthSourceFrame = width*height*3/2; rewind(_sourceFile); ASSERT_TRUE(_sourceFile != NULL) << @@ -244,12 +251,15 @@ TEST_F(VideoProcessingModuleTest, Resampler) _vpm->EnableTemporalDecimation(false); // Reading test frame - VideoFrame sourceFrame; - ASSERT_EQ(0, sourceFrame.VerifyAndAllocate(lengthSourceFrame)); - EXPECT_GT(fread(sourceFrame.Buffer(), 1, lengthSourceFrame, _sourceFile), 0u); - ASSERT_EQ(0, sourceFrame.SetLength(lengthSourceFrame)); - sourceFrame.SetHeight(height); - sourceFrame.SetWidth(width); + I420VideoFrame sourceFrame; + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + sourceFrame.CreateFrame(_size_y, video_buffer.get(), + _size_uv, video_buffer.get() + _size_y, + _size_uv, video_buffer.get() + _size_y + _size_uv, + _width, _height, + _width, _half_width, _half_width); for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) { @@ -282,8 +292,6 @@ TEST_F(VideoProcessingModuleTest, Resampler) avgRuntime += accTicks.Microseconds(); } - sourceFrame.Free(); - printf("\nAverage run time = %d us / frame\n", //static_cast(avgRuntime / frameNum / NumRuns)); static_cast(avgRuntime)); @@ -292,12 +300,12 @@ TEST_F(VideoProcessingModuleTest, Resampler) static_cast(minRuntime)); } -void TestSize(const VideoFrame& source_frame, int target_width, +void TestSize(const I420VideoFrame& source_frame, int target_width, int target_height, int mode, double expected_psnr, VideoProcessingModule* vpm) { - int source_width = source_frame.Width(); - int source_height = source_frame.Height(); - VideoFrame* out_frame = NULL; + int source_width = source_frame.width(); + int source_height = source_frame.height(); + I420VideoFrame* out_frame = NULL; ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); @@ -309,12 +317,6 @@ void TestSize(const VideoFrame& source_frame, int target_width, // (3) write out the processed frame for viewing. if (target_width != static_cast(source_width) || target_height != static_cast(source_height)) { - int target_half_width = (target_width + 1) >> 1; - int target_half_height = (target_height + 1) >> 1; - int required_size_resampled = target_width * target_height + - 2 * (target_half_width * target_half_height); - ASSERT_EQ(required_size_resampled, static_cast(out_frame->Length())); - // Write the processed frame to file for visual inspection. std::ostringstream filename; filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << @@ -323,15 +325,14 @@ void TestSize(const VideoFrame& source_frame, int target_width, std::cout << "Watch " << filename.str() << " and verify that it is okay." << std::endl; FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (fwrite(out_frame->Buffer(), 1, - out_frame->Length(), stand_alone_file) != out_frame->Length()) { + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { fprintf(stderr, "Failed to write frame for scaling to width/height: " " %d %d \n", target_width, target_height); return; } fclose(stand_alone_file); - VideoFrame resampled_source_frame; + I420VideoFrame resampled_source_frame; resampled_source_frame.CopyFrame(*out_frame); // Scale |resampled_source_frame| back to original/source size. @@ -349,24 +350,36 @@ void TestSize(const VideoFrame& source_frame, int target_width, std::cout << "Watch " << filename2.str() << " and verify that it is okay." << std::endl; stand_alone_file = fopen(filename2.str().c_str(), "wb"); - if (fwrite(out_frame->Buffer(), 1, - out_frame->Length(), stand_alone_file) != out_frame->Length()) { + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { fprintf(stderr, "Failed to write frame for scaling to width/height " - "%d %d \n", source_width, source_height); + "%d %d \n", source_width, source_height); return; } fclose(stand_alone_file); // Compute the PSNR and check expectation. - double psnr = I420PSNR(source_frame.Buffer(), out_frame->Buffer(), - source_width, source_height); + double psnr = I420PSNR(&source_frame, out_frame); EXPECT_GT(psnr, expected_psnr); printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " "source which is scaled down/up to: %d %d, and back to source size \n", psnr, source_width, source_height, target_width, target_height); + } +} - resampled_source_frame.Free(); +bool CompareFrames(const webrtc::I420VideoFrame& frame1, + const webrtc::I420VideoFrame& frame2) { + for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { + webrtc::PlaneType plane_type = static_cast(plane); + int allocated_size1 = frame1.allocated_size(plane_type); + int allocated_size2 = frame2.allocated_size(plane_type); + if (allocated_size1 != allocated_size2) + return false; + const uint8_t* plane_buffer1 = frame1.buffer(plane_type); + const uint8_t* plane_buffer2 = frame2.buffer(plane_type); + if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) + return false; } + return true; } } // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h index 2363e1a146..67496d11c6 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h @@ -36,10 +36,13 @@ protected: } VideoProcessingModule* _vpm; FILE* _sourceFile; - VideoFrame _videoFrame; - const WebRtc_UWord32 _width; - const WebRtc_UWord32 _height; - const WebRtc_UWord32 _frameLength; + I420VideoFrame _videoFrame; + const int _width; + const int _half_width; + const int _height; + const int _size_y; + const int _size_uv; + const unsigned int _frame_length; }; } // namespace webrtc -- cgit v1.2.3 From 1997ddb7137d7a18edcef4969075f19c9b5ac811 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Wed, 24 Oct 2012 21:34:21 +0000 Subject: Fix valgrind issue introduced in r2983 Review URL: https://webrtc-codereview.appspot.com/936004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2986 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/video_processing/main/test/unit_test/unit_test.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index 2b06ccd6ea..967a8f0af4 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -33,10 +33,10 @@ VideoProcessingModuleTest::VideoProcessingModuleTest() : _vpm(NULL), _sourceFile(NULL), _width(352), - _half_width(_width / 2), + _half_width((_width + 1) / 2), _height(288), _size_y(_width * _height), - _size_uv(_half_width * _height /2), + _size_uv(_half_width * ((_height + 1) / 2)), _frame_length(CalcBufferSize(kI420, _width, _height)) { } @@ -72,6 +72,9 @@ void VideoProcessingModuleTest::TearDown() TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { VideoProcessingModule::FrameStats stats; + memset(_videoFrame.buffer(kYPlane), 0, _size_y); + memset(_videoFrame.buffer(kUPlane), 0, _size_uv); + memset(_videoFrame.buffer(kVPlane), 0, _size_uv); ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); // Video frame with unallocated buffer. I420VideoFrame videoFrame; -- cgit v1.2.3 From 9169b51fe722081b8ea698e84a62b8335969f39c Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 25 Oct 2012 15:23:11 +0000 Subject: Fixing vpm valgrind issues introduced in r2893 Review URL: https://webrtc-codereview.appspot.com/933007 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2996 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/video_processing/main/test/unit_test/unit_test.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index 967a8f0af4..0a0fa1f507 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -71,11 +71,8 @@ void VideoProcessingModuleTest::TearDown() TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { + // TODO(mikhal/stefan): Do we need this one? VideoProcessingModule::FrameStats stats; - memset(_videoFrame.buffer(kYPlane), 0, _size_y); - memset(_videoFrame.buffer(kUPlane), 0, _size_uv); - memset(_videoFrame.buffer(kVPlane), 0, _size_uv); - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); // Video frame with unallocated buffer. I420VideoFrame videoFrame; videoFrame.set_width(_width); @@ -112,7 +109,6 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) TEST_F(VideoProcessingModuleTest, HandleBadSize) { VideoProcessingModule::FrameStats stats; - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); _videoFrame.ResetSize(); _videoFrame.set_width(_width); -- cgit v1.2.3 From 4cebe6cded9e3c8a1177f69cb71f48f993df3e5a Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Wed, 7 Nov 2012 13:37:19 +0000 Subject: Made TickTime immutable, rewrote tick utils to be fakeable. BUG= Review URL: https://webrtc-codereview.appspot.com/798004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3053 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/video_processing/main/test/unit_test/deflickering_test.cc | 2 +- webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc | 2 +- webrtc/modules/video_processing/main/test/unit_test/unit_test.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index bf284fcb61..d7833f9200 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -69,7 +69,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); t1 = TickTime::Now(); - accTicks += t1 - t0; + accTicks += (t1 - t0); if (runIdx == 0) { diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 1d0f9a28db..b3d1259d60 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -107,7 +107,7 @@ TEST_F(VideoProcessingModuleTest, Denoising) t0 = TickTime::Now(); ASSERT_GE(modifiedPixels = _vpm->Denoising(&_videoFrame), 0); t1 = TickTime::Now(); - accTicks += t1 - t0; + accTicks += (t1 - t0); if (runIdx == 0) { diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index 0a0fa1f507..b340b6f8ff 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -14,7 +14,7 @@ #include "common_video/libyuv/include/webrtc_libyuv.h" #include "system_wrappers/interface/tick_util.h" -#include "testsupport/fileutils.h" +#include "test/testsupport/fileutils.h" namespace webrtc { @@ -283,7 +283,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) // stop timer t1 = TickTime::Now(); - accTicks += t1 - t0; + accTicks += (t1 - t0); if (accTicks.Microseconds() < minRuntime || runIdx == 0) { minRuntime = accTicks.Microseconds(); -- cgit v1.2.3 From 2a749d31081259b1138ab32f1ed8c20ec4b0cccf Mon Sep 17 00:00:00 2001 From: "wu@webrtc.org" Date: Thu, 8 Nov 2012 01:07:21 +0000 Subject: Verify output frame timestamp in VideoProcessingModuleTest.Resampler. TEST=unit tests BUG=1069 Review URL: https://webrtc-codereview.appspot.com/964014 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3063 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/video_processing/main/test/unit_test/unit_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index b340b6f8ff..c29808a7ea 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -265,6 +265,10 @@ TEST_F(VideoProcessingModuleTest, Resampler) // initiate test timer t0 = TickTime::Now(); + // Init the sourceFrame with a timestamp. + sourceFrame.set_render_time_ms(t0.MillisecondTimestamp()); + sourceFrame.set_timestamp(t0.MillisecondTimestamp() * 90); + // Test scaling to different sizes: source is of |width|/|height| = 352/288. // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). TestSize(sourceFrame, 100, 50, 3, 24.0, _vpm); @@ -309,6 +313,11 @@ void TestSize(const I420VideoFrame& source_frame, int target_width, ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); + if (out_frame) { + EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); + EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); + } + // If the frame was resampled (scale changed) then: // (1) verify the new size and write out processed frame for viewing. // (2) scale the resampled frame (|out_frame|) back to the original size and -- cgit v1.2.3 From 4493db5a3e8f4200f20080a8a0aeaa18f90508a0 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 13 Dec 2012 18:25:36 +0000 Subject: vpm: removing unnecessary memcpy TEST=trybots BUG=1128 Review URL: https://webrtc-codereview.appspot.com/966038 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3284 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/unit_test.cc | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index c29808a7ea..e4775fc069 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -213,20 +213,31 @@ TEST_F(VideoProcessingModuleTest, FrameStats) TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { - // Disable temporal sampling + // Disable temporal sampling. + int resolution = 100; _vpm->EnableTemporalDecimation(false); - ASSERT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 15)); + EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); // Revert _vpm->EnableTemporalDecimation(true); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); - // Disable spatial sampling + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + // Disable spatial sampling. _vpm->SetInputFrameResampleMode(kNoRescaling); - ASSERT_EQ(VPM_OK, _vpm->SetTargetResolution(100, 100, 30)); - I420VideoFrame *outFrame = NULL; - ASSERT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - // No rescaling=> output frame = NULL - ASSERT_TRUE(outFrame == NULL); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + I420VideoFrame* outFrame = NULL; + // Set rescaling => output frame != NULL. + _vpm->SetInputFrameResampleMode(kFastRescaling); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_FALSE(outFrame == NULL); + if (outFrame) { + EXPECT_EQ(resolution, outFrame->width()); + EXPECT_EQ(resolution, outFrame->height()); + } + // No rescaling=> output frame = NULL. + _vpm->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_TRUE(outFrame == NULL); } TEST_F(VideoProcessingModuleTest, Resampler) -- cgit v1.2.3 From 96dc6270d47a730357ef4711f89cd3b20b4522c1 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 13 Dec 2012 19:53:26 +0000 Subject: vpm unit test: Diasble frame dropping in tests (follow up on r3284) BUG= Review URL: https://webrtc-codereview.appspot.com/991005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3285 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/video_processing/main/test/unit_test/unit_test.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index e4775fc069..dc7794411f 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -213,13 +213,11 @@ TEST_F(VideoProcessingModuleTest, FrameStats) TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { - // Disable temporal sampling. - int resolution = 100; + // Disable temporal sampling (frame dropping). _vpm->EnableTemporalDecimation(false); + int resolution = 100; EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); - // Revert - _vpm->EnableTemporalDecimation(true); EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); // Disable spatial sampling. _vpm->SetInputFrameResampleMode(kNoRescaling); -- cgit v1.2.3 From 658d423e81e32406fab0d5a404003edbba159745 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Tue, 8 Jan 2013 19:19:59 +0000 Subject: Using Convert in lieu of ExtractBuffer: Less error prone (as we don't need to compute buffer sizes etc.). This cl is first in a series (doing all of WebRtc would make it quite a big cl). While at it, fixing a few headers. BUG=988 Review URL: https://webrtc-codereview.appspot.com/995014 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3343 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 32 ++++----- .../main/test/unit_test/color_enhancement_test.cc | 45 ++++++------- .../main/test/unit_test/content_metrics_test.cc | 11 ++-- .../main/test/unit_test/deflickering_test.cc | 19 +++--- .../main/test/unit_test/denoising_test.cc | 9 +-- .../main/test/unit_test/unit_test.cc | 77 ++++++++++------------ 6 files changed, 81 insertions(+), 112 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index ffb1c41eae..28561ba09a 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -8,8 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "unit_test.h" -#include "video_processing.h" +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" using namespace webrtc; @@ -22,12 +23,9 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); frameNum++; VideoProcessingModule::FrameStats stats; ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); @@ -53,12 +51,9 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) _frame_length && frameNum < 300) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); frameNum++; WebRtc_UWord8* frame = _videoFrame.buffer(kYPlane); @@ -96,12 +91,9 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length && frameNum < 300) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); frameNum++; WebRtc_UWord8* y_plane = _videoFrame.buffer(kYPlane); diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index 85029fea40..bd48366e58 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -43,12 +43,10 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); frameNum++; t0 = TickTime::Now(); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&_videoFrame)); @@ -84,26 +82,23 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_EQ(refLen, testLen) << "File lengths differ."; I420VideoFrame refVideoFrame; + refVideoFrame.CreateEmptyFrame(_width, _height, + _width, _half_width, _half_width); // Compare frame-by-frame. scoped_array ref_buffer(new uint8_t[_frame_length]); while (fread(video_buffer.get(), 1, _frame_length, modFile) == _frame_length) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); - ASSERT_EQ(_frame_length, fread(ref_buffer.get(), 1, _frame_length, - refFile)); - refVideoFrame.CreateFrame(_size_y, ref_buffer.get(), - _size_uv, ref_buffer.get() + _size_y, - _size_uv, ref_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + ASSERT_EQ(_frame_length, fread(ref_buffer.get(), 1, _frame_length, + refFile)); + EXPECT_EQ(0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &refVideoFrame)); EXPECT_EQ(0, memcmp(_videoFrame.buffer(kYPlane), refVideoFrame.buffer(kYPlane), _size_y)); @@ -126,11 +121,11 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) memset(testFrame.get(), 128, _frame_length); I420VideoFrame testVideoFrame; - testVideoFrame.CreateFrame(_size_y, testFrame.get(), - _size_uv, testFrame.get() + _size_y, - _size_uv, testFrame.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + testVideoFrame.CreateEmptyFrame(_width, _height, + _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, testFrame.get(), 0, 0, + _width, _height, 0, kRotateNone, + &testVideoFrame)); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index cf784c74ea..063a7afb3d 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "modules/video_processing/main/interface/video_processing.h" #include "modules/video_processing/main/source/content_analysis.h" #include "modules/video_processing/main/test/unit_test/unit_test.h" @@ -27,12 +28,10 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); _cM_c = _ca_c.ComputeContentMetrics(_videoFrame); _cM_SSE = _ca_sse.ComputeContentMetrics(_videoFrame); diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index d7833f9200..f47ee16208 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -11,11 +11,11 @@ #include #include -#include "common_video/libyuv/include/webrtc_libyuv.h" -#include "modules/video_processing/main/interface/video_processing.h" -#include "modules/video_processing/main/test/unit_test/unit_test.h" -#include "system_wrappers/interface/tick_util.h" -#include "testsupport/fileutils.h" +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/fileutils.h" namespace webrtc { @@ -56,12 +56,9 @@ TEST_F(VideoProcessingModuleTest, Deflickering) _frame_length) { frameNum++; - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + - _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); _videoFrame.set_timestamp(timeStamp); t0 = TickTime::Now(); diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index b3d1259d60..5a1d5460ce 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -52,12 +52,9 @@ TEST_F(VideoProcessingModuleTest, Denoising) while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) { - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, - video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); frameNum++; WebRtc_UWord8* sourceBuffer = _videoFrame.buffer(kYPlane); diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index dc7794411f..da9cdfde14 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -95,11 +95,9 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) scoped_array video_buffer(new uint8_t[_frame_length]); ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); @@ -139,11 +137,9 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) scoped_array video_buffer(new uint8_t[_frame_length]); ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - ASSERT_EQ(0, _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); ASSERT_EQ(0, videoFrame2.CopyFrame(_videoFrame)); ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); @@ -155,11 +151,10 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); videoFrame2.CopyFrame(_videoFrame); EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); @@ -169,11 +164,9 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); videoFrame2.CopyFrame(_videoFrame); ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); @@ -188,11 +181,9 @@ TEST_F(VideoProcessingModuleTest, FrameStats) scoped_array video_buffer(new uint8_t[_frame_length]); ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - _videoFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); EXPECT_FALSE(_vpm->ValidFrameStats(stats)); EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); @@ -259,15 +250,13 @@ TEST_F(VideoProcessingModuleTest, Resampler) _vpm->EnableTemporalDecimation(false); // Reading test frame - I420VideoFrame sourceFrame; scoped_array video_buffer(new uint8_t[_frame_length]); ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, _sourceFile)); - sourceFrame.CreateFrame(_size_y, video_buffer.get(), - _size_uv, video_buffer.get() + _size_y, - _size_uv, video_buffer.get() + _size_y + _size_uv, - _width, _height, - _width, _half_width, _half_width); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) { @@ -275,24 +264,24 @@ TEST_F(VideoProcessingModuleTest, Resampler) t0 = TickTime::Now(); // Init the sourceFrame with a timestamp. - sourceFrame.set_render_time_ms(t0.MillisecondTimestamp()); - sourceFrame.set_timestamp(t0.MillisecondTimestamp() * 90); + _videoFrame.set_render_time_ms(t0.MillisecondTimestamp()); + _videoFrame.set_timestamp(t0.MillisecondTimestamp() * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). - TestSize(sourceFrame, 100, 50, 3, 24.0, _vpm); - TestSize(sourceFrame, 352/4, 288/4, 3, 25.2, _vpm); - TestSize(sourceFrame, 352/2, 288/2, 3, 28.1, _vpm); - TestSize(sourceFrame, 352, 288, 3, -1, _vpm); // no resampling. - TestSize(sourceFrame, 2*352, 2*288, 3, 32.2, _vpm); - TestSize(sourceFrame, 400, 256, 3, 31.3, _vpm); - TestSize(sourceFrame, 480, 640, 3, 32.15, _vpm); - TestSize(sourceFrame, 960, 720, 3, 32.2, _vpm); - TestSize(sourceFrame, 1280, 720, 3, 32.15, _vpm); + TestSize(_videoFrame, 100, 50, 3, 24.0, _vpm); + TestSize(_videoFrame, 352/4, 288/4, 3, 25.2, _vpm); + TestSize(_videoFrame, 352/2, 288/2, 3, 28.1, _vpm); + TestSize(_videoFrame, 352, 288, 3, -1, _vpm); // no resampling. + TestSize(_videoFrame, 2*352, 2*288, 3, 32.2, _vpm); + TestSize(_videoFrame, 400, 256, 3, 31.3, _vpm); + TestSize(_videoFrame, 480, 640, 3, 32.15, _vpm); + TestSize(_videoFrame, 960, 720, 3, 32.2, _vpm); + TestSize(_videoFrame, 1280, 720, 3, 32.15, _vpm); // Upsampling to odd size. - TestSize(sourceFrame, 501, 333, 3, 32.05, _vpm); + TestSize(_videoFrame, 501, 333, 3, 32.05, _vpm); // Downsample to odd size. - TestSize(sourceFrame, 281, 175, 3, 29.3, _vpm); + TestSize(_videoFrame, 281, 175, 3, 29.3, _vpm); // stop timer t1 = TickTime::Now(); -- cgit v1.2.3 From 1ab45f6dd587b6c81839bd2f9b477721c9011b67 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 9 Apr 2013 13:38:10 +0000 Subject: WebRtc_Word32 -> int32_t in video_processing/ BUG=314 Review URL: https://webrtc-codereview.appspot.com/1297006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3800 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/brightness_detection_test.cc | 18 +++++++++--------- .../main/test/unit_test/color_enhancement_test.cc | 4 ++-- .../main/test/unit_test/deflickering_test.cc | 12 ++++++------ .../main/test/unit_test/denoising_test.cc | 18 +++++++++--------- .../video_processing/main/test/unit_test/unit_test.cc | 6 +++--- 5 files changed, 29 insertions(+), 29 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index 28561ba09a..1a5b8f39ff 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -16,9 +16,9 @@ using namespace webrtc; TEST_F(VideoProcessingModuleTest, BrightnessDetection) { - WebRtc_UWord32 frameNum = 0; - WebRtc_Word32 brightnessWarning = 0; - WebRtc_UWord32 warningCount = 0; + uint32_t frameNum = 0; + int32_t brightnessWarning = 0; + uint32_t warningCount = 0; scoped_array video_buffer(new uint8_t[_frame_length]); while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) @@ -56,8 +56,8 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) 0, kRotateNone, &_videoFrame)); frameNum++; - WebRtc_UWord8* frame = _videoFrame.buffer(kYPlane); - WebRtc_UWord32 yTmp = 0; + uint8_t* frame = _videoFrame.buffer(kYPlane); + uint32_t yTmp = 0; for (int yIdx = 0; yIdx < _width * _height; yIdx++) { yTmp = frame[yIdx] << 1; @@ -65,7 +65,7 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) { yTmp = 255; } - frame[yIdx] = static_cast(yTmp); + frame[yIdx] = static_cast(yTmp); } VideoProcessingModule::FrameStats stats; @@ -96,12 +96,12 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) 0, kRotateNone, &_videoFrame)); frameNum++; - WebRtc_UWord8* y_plane = _videoFrame.buffer(kYPlane); - WebRtc_Word32 yTmp = 0; + uint8_t* y_plane = _videoFrame.buffer(kYPlane); + int32_t yTmp = 0; for (int yIdx = 0; yIdx < _width * _height; yIdx++) { yTmp = y_plane[yIdx] >> 1; - y_plane[yIdx] = static_cast(yTmp); + y_plane[yIdx] = static_cast(yTmp); } VideoProcessingModule::FrameStats stats; diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index bd48366e58..34fd163f4d 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -38,7 +38,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) FILE* modFile = fopen(output_file.c_str(), "w+b"); ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; - WebRtc_UWord32 frameNum = 0; + uint32_t frameNum = 0; scoped_array video_buffer(new uint8_t[_frame_length]); while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == _frame_length) @@ -114,7 +114,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) // Verify that all color pixels are enhanced, and no luminance values are // altered. - scoped_array testFrame(new WebRtc_UWord8[_frame_length]); + scoped_array testFrame(new uint8_t[_frame_length]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index f47ee16208..15082751ae 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -22,11 +22,11 @@ namespace webrtc { TEST_F(VideoProcessingModuleTest, Deflickering) { enum { NumRuns = 30 }; - WebRtc_UWord32 frameNum = 0; - const WebRtc_UWord32 frameRate = 15; + uint32_t frameNum = 0; + const uint32_t frameRate = 15; - WebRtc_Word64 minRuntime = 0; - WebRtc_Word64 avgRuntime = 0; + int64_t minRuntime = 0; + int64_t avgRuntime = 0; // Close automatically opened Foreman. fclose(_sourceFile); @@ -44,12 +44,12 @@ TEST_F(VideoProcessingModuleTest, Deflickering) printf("\nRun time [us / frame]:\n"); scoped_array video_buffer(new uint8_t[_frame_length]); - for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) { TickTime t0; TickTime t1; TickInterval accTicks; - WebRtc_UWord32 timeStamp = 1; + uint32_t timeStamp = 1; frameNum = 0; while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 5a1d5460ce..fab064eeac 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -22,10 +22,10 @@ namespace webrtc { TEST_F(VideoProcessingModuleTest, Denoising) { enum { NumRuns = 10 }; - WebRtc_UWord32 frameNum = 0; + uint32_t frameNum = 0; - WebRtc_Word64 minRuntime = 0; - WebRtc_Word64 avgRuntime = 0; + int64_t minRuntime = 0; + int64_t avgRuntime = 0; const std::string denoise_filename = webrtc::test::OutputPath() + "denoise_testfile.yuv"; @@ -40,12 +40,12 @@ TEST_F(VideoProcessingModuleTest, Denoising) "Could not open noisy file: " << noise_filename << "\n"; printf("\nRun time [us / frame]:\n"); - for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) { TickTime t0; TickTime t1; TickInterval accTicks; - WebRtc_Word32 modifiedPixels = 0; + int32_t modifiedPixels = 0; frameNum = 0; scoped_array video_buffer(new uint8_t[_frame_length]); @@ -56,7 +56,7 @@ TEST_F(VideoProcessingModuleTest, Denoising) _width, _height, 0, kRotateNone, &_videoFrame)); frameNum++; - WebRtc_UWord8* sourceBuffer = _videoFrame.buffer(kYPlane); + uint8_t* sourceBuffer = _videoFrame.buffer(kYPlane); // Add noise to a part in video stream // Random noise @@ -64,10 +64,10 @@ TEST_F(VideoProcessingModuleTest, Denoising) for (int ir = 0; ir < _height; ir++) { - WebRtc_UWord32 ik = ir * _width; + uint32_t ik = ir * _width; for (int ic = 0; ic < _width; ic++) { - WebRtc_UWord8 r = rand() % 16; + uint8_t r = rand() % 16; r -= 8; if (ir < _height / 4) r = 0; @@ -78,7 +78,7 @@ TEST_F(VideoProcessingModuleTest, Denoising) if (ic >= 3 * _width / 4) r = 0; - /*WebRtc_UWord8 pixelValue = 0; + /*uint8_t pixelValue = 0; if (ir >= _height / 2) { // Region 3 or 4 pixelValue = 170; diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index da9cdfde14..e22d1d04ab 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -233,8 +233,8 @@ TEST_F(VideoProcessingModuleTest, Resampler) { enum { NumRuns = 1 }; - WebRtc_Word64 minRuntime = 0; - WebRtc_Word64 avgRuntime = 0; + int64_t minRuntime = 0; + int64_t avgRuntime = 0; TickTime t0; TickTime t1; @@ -258,7 +258,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) _width, _height, 0, kRotateNone, &_videoFrame)); - for (WebRtc_UWord32 runIdx = 0; runIdx < NumRuns; runIdx++) + for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) { // initiate test timer t0 = TickTime::Now(); -- cgit v1.2.3 From 6f3d8fcfc08686a9e8852ad225d54cca6e197875 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Mon, 27 May 2013 14:12:16 +0000 Subject: Include files from webrtc/.. paths in video_processing/ BUG=1662 R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1558004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4109 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/color_enhancement_test.cc | 10 +++++----- .../main/test/unit_test/content_metrics_test.cc | 6 +++--- .../video_processing/main/test/unit_test/denoising_test.cc | 10 +++++----- .../modules/video_processing/main/test/unit_test/unit_test.cc | 8 ++++---- .../modules/video_processing/main/test/unit_test/unit_test.h | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index 34fd163f4d..f8129e3bdb 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -11,11 +11,11 @@ #include #include -#include "common_video/libyuv/include/webrtc_libyuv.h" -#include "modules/video_processing/main/interface/video_processing.h" -#include "modules/video_processing/main/test/unit_test/unit_test.h" -#include "system_wrappers/interface/tick_util.h" -#include "testsupport/fileutils.h" +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/fileutils.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 063a7afb3d..e73eaa32c2 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -9,9 +9,9 @@ */ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "modules/video_processing/main/interface/video_processing.h" -#include "modules/video_processing/main/source/content_analysis.h" -#include "modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/modules/video_processing/main/source/content_analysis.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index fab064eeac..8d6ea477db 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -11,11 +11,11 @@ #include #include -#include "common_video/libyuv/include/webrtc_libyuv.h" -#include "modules/video_processing/main/interface/video_processing.h" -#include "modules/video_processing/main/test/unit_test/unit_test.h" -#include "system_wrappers/interface/tick_util.h" -#include "testsupport/fileutils.h" +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/fileutils.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc index e22d1d04ab..eea8081fd3 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" #include -#include "common_video/libyuv/include/webrtc_libyuv.h" -#include "system_wrappers/interface/tick_util.h" -#include "test/testsupport/fileutils.h" +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/fileutils.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h index 67496d11c6..62c40398b4 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h +++ b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h @@ -11,10 +11,10 @@ #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H #define WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H -#include "gtest/gtest.h" -#include "modules/video_processing/main/interface/video_processing.h" -#include "system_wrappers/interface/trace.h" -#include "testsupport/fileutils.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/system_wrappers/interface/trace.h" +#include "webrtc/test/testsupport/fileutils.h" namespace webrtc { -- cgit v1.2.3 From c66aaaf921f0bab53721532bb2bf5ac76be6d860 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Wed, 3 Jul 2013 07:56:33 +0000 Subject: Rename unit_test.{cc,h} under module_unittest. Squelches the following Windows trybot warning: warning LNK4042: object specified more than once; extras ignored BUG= R=andrew@webrtc.org, stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1758004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4288 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 2 +- .../main/test/unit_test/color_enhancement_test.cc | 2 +- .../main/test/unit_test/content_metrics_test.cc | 2 +- .../main/test/unit_test/deflickering_test.cc | 2 +- .../main/test/unit_test/denoising_test.cc | 2 +- .../main/test/unit_test/unit_test.cc | 391 --------------------- .../main/test/unit_test/unit_test.h | 50 --- .../test/unit_test/video_processing_unittest.cc | 391 +++++++++++++++++++++ .../test/unit_test/video_processing_unittest.h | 50 +++ 9 files changed, 446 insertions(+), 446 deletions(-) delete mode 100644 webrtc/modules/video_processing/main/test/unit_test/unit_test.cc delete mode 100644 webrtc/modules/video_processing/main/test/unit_test/unit_test.h create mode 100644 webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc create mode 100644 webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index 1a5b8f39ff..d17ade9696 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -10,7 +10,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" using namespace webrtc; diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index f8129e3bdb..ea1ed41c49 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -13,7 +13,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index e73eaa32c2..26080da784 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -11,7 +11,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" #include "webrtc/modules/video_processing/main/source/content_analysis.h" -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" namespace webrtc { diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 15082751ae..48afcf569d 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -13,7 +13,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 8d6ea477db..71d133bdfc 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -13,7 +13,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc b/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc deleted file mode 100644 index eea8081fd3..0000000000 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.cc +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/video_processing/main/test/unit_test/unit_test.h" - -#include - -#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/system_wrappers/interface/tick_util.h" -#include "webrtc/test/testsupport/fileutils.h" - -namespace webrtc { - -// The |sourceFrame| is scaled to |target_width|,|target_height|, using the -// filter mode set to |mode|. The |expected_psnr| is used to verify basic -// quality when the resampled frame is scaled back up/down to the -// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than -// actual PSNR verified under the same conditions. -void TestSize(const I420VideoFrame& sourceFrame, int target_width, - int target_height, int mode, double expected_psnr, - VideoProcessingModule* vpm); -bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); - -VideoProcessingModuleTest::VideoProcessingModuleTest() : - _vpm(NULL), - _sourceFile(NULL), - _width(352), - _half_width((_width + 1) / 2), - _height(288), - _size_y(_width * _height), - _size_uv(_half_width * ((_height + 1) / 2)), - _frame_length(CalcBufferSize(kI420, _width, _height)) -{ -} - -void VideoProcessingModuleTest::SetUp() -{ - _vpm = VideoProcessingModule::Create(0); - ASSERT_TRUE(_vpm != NULL); - - ASSERT_EQ(0, _videoFrame.CreateEmptyFrame(_width, _height, _width, - _half_width, _half_width)); - - const std::string video_file = - webrtc::test::ResourcePath("foreman_cif", "yuv"); - _sourceFile = fopen(video_file.c_str(),"rb"); - ASSERT_TRUE(_sourceFile != NULL) << - "Cannot read source file: " + video_file + "\n"; -} - -void VideoProcessingModuleTest::TearDown() -{ - if (_sourceFile != NULL) { - ASSERT_EQ(0, fclose(_sourceFile)); - } - _sourceFile = NULL; - - if (_vpm != NULL) { - VideoProcessingModule::Destroy(_vpm); - } - _vpm = NULL; -} - -TEST_F(VideoProcessingModuleTest, HandleNullBuffer) -{ - // TODO(mikhal/stefan): Do we need this one? - VideoProcessingModule::FrameStats stats; - // Video frame with unallocated buffer. - I420VideoFrame videoFrame; - videoFrame.set_width(_width); - videoFrame.set_height(_height); - - EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, videoFrame)); - - EXPECT_EQ(-1, _vpm->ColorEnhancement(&videoFrame)); - - EXPECT_EQ(-1, _vpm->Deflickering(&videoFrame, &stats)); - - EXPECT_EQ(-1, _vpm->Denoising(&videoFrame)); - - EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats)); -} - -TEST_F(VideoProcessingModuleTest, HandleBadStats) -{ - VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - - EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); - - EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); -} - -TEST_F(VideoProcessingModuleTest, HandleBadSize) -{ - VideoProcessingModule::FrameStats stats; - - _videoFrame.ResetSize(); - _videoFrame.set_width(_width); - _videoFrame.set_height(0); - EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); - - EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); - - EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); - - EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); - - EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); - - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); - - I420VideoFrame *outFrame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(_videoFrame, - &outFrame)); -} - -TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) -{ - I420VideoFrame videoFrame2; - VideoProcessingModule::FrameStats stats; - // Only testing non-static functions here. - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_EQ(0, videoFrame2.CopyFrame(_videoFrame)); - ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); - _vpm->Reset(); - // Retrieve frame stats again in case Deflickering() has zeroed them. - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, videoFrame2)); - ASSERT_EQ(0, _vpm->Deflickering(&videoFrame2, &stats)); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); - - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - videoFrame2.CopyFrame(_videoFrame); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); - ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); - _vpm->Reset(); - ASSERT_GE(_vpm->Denoising(&videoFrame2), 0); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); - - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - videoFrame2.CopyFrame(_videoFrame); - ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); - _vpm->Reset(); - ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); -} - -TEST_F(VideoProcessingModuleTest, FrameStats) -{ - VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - - EXPECT_FALSE(_vpm->ValidFrameStats(stats)); - EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - EXPECT_TRUE(_vpm->ValidFrameStats(stats)); - - printf("\nFrameStats\n"); - printf("mean: %u\nnumPixels: %u\nsubSamplWidth: " - "%u\nsumSamplHeight: %u\nsum: %u\n\n", - static_cast(stats.mean), - static_cast(stats.numPixels), - static_cast(stats.subSamplHeight), - static_cast(stats.subSamplWidth), - static_cast(stats.sum)); - - _vpm->ClearFrameStats(&stats); - EXPECT_FALSE(_vpm->ValidFrameStats(stats)); -} - -TEST_F(VideoProcessingModuleTest, PreprocessorLogic) -{ - // Disable temporal sampling (frame dropping). - _vpm->EnableTemporalDecimation(false); - int resolution = 100; - EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); - // Disable spatial sampling. - _vpm->SetInputFrameResampleMode(kNoRescaling); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); - I420VideoFrame* outFrame = NULL; - // Set rescaling => output frame != NULL. - _vpm->SetInputFrameResampleMode(kFastRescaling); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); - EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - EXPECT_FALSE(outFrame == NULL); - if (outFrame) { - EXPECT_EQ(resolution, outFrame->width()); - EXPECT_EQ(resolution, outFrame->height()); - } - // No rescaling=> output frame = NULL. - _vpm->SetInputFrameResampleMode(kNoRescaling); - EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - EXPECT_TRUE(outFrame == NULL); -} - -TEST_F(VideoProcessingModuleTest, Resampler) -{ - enum { NumRuns = 1 }; - - int64_t minRuntime = 0; - int64_t avgRuntime = 0; - - TickTime t0; - TickTime t1; - TickInterval accTicks; - - rewind(_sourceFile); - ASSERT_TRUE(_sourceFile != NULL) << - "Cannot read input file \n"; - - // CA not needed here - _vpm->EnableContentAnalysis(false); - // no temporal decimation - _vpm->EnableTemporalDecimation(false); - - // Reading test frame - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - - for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) - { - // initiate test timer - t0 = TickTime::Now(); - - // Init the sourceFrame with a timestamp. - _videoFrame.set_render_time_ms(t0.MillisecondTimestamp()); - _videoFrame.set_timestamp(t0.MillisecondTimestamp() * 90); - - // Test scaling to different sizes: source is of |width|/|height| = 352/288. - // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). - TestSize(_videoFrame, 100, 50, 3, 24.0, _vpm); - TestSize(_videoFrame, 352/4, 288/4, 3, 25.2, _vpm); - TestSize(_videoFrame, 352/2, 288/2, 3, 28.1, _vpm); - TestSize(_videoFrame, 352, 288, 3, -1, _vpm); // no resampling. - TestSize(_videoFrame, 2*352, 2*288, 3, 32.2, _vpm); - TestSize(_videoFrame, 400, 256, 3, 31.3, _vpm); - TestSize(_videoFrame, 480, 640, 3, 32.15, _vpm); - TestSize(_videoFrame, 960, 720, 3, 32.2, _vpm); - TestSize(_videoFrame, 1280, 720, 3, 32.15, _vpm); - // Upsampling to odd size. - TestSize(_videoFrame, 501, 333, 3, 32.05, _vpm); - // Downsample to odd size. - TestSize(_videoFrame, 281, 175, 3, 29.3, _vpm); - - // stop timer - t1 = TickTime::Now(); - accTicks += (t1 - t0); - - if (accTicks.Microseconds() < minRuntime || runIdx == 0) { - minRuntime = accTicks.Microseconds(); - } - avgRuntime += accTicks.Microseconds(); - } - - printf("\nAverage run time = %d us / frame\n", - //static_cast(avgRuntime / frameNum / NumRuns)); - static_cast(avgRuntime)); - printf("Min run time = %d us / frame\n\n", - //static_cast(minRuntime / frameNum)); - static_cast(minRuntime)); -} - -void TestSize(const I420VideoFrame& source_frame, int target_width, - int target_height, int mode, double expected_psnr, - VideoProcessingModule* vpm) { - int source_width = source_frame.width(); - int source_height = source_frame.height(); - I420VideoFrame* out_frame = NULL; - - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); - - if (out_frame) { - EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); - EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); - } - - // If the frame was resampled (scale changed) then: - // (1) verify the new size and write out processed frame for viewing. - // (2) scale the resampled frame (|out_frame|) back to the original size and - // compute PSNR relative to |source_frame| (for automatic verification). - // (3) write out the processed frame for viewing. - if (target_width != static_cast(source_width) || - target_height != static_cast(source_height)) { - // Write the processed frame to file for visual inspection. - std::ostringstream filename; - filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << source_width << "x" << source_height << "_to_" << - target_width << "x" << target_height << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename.str() << " and verify that it is okay." - << std::endl; - FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height: " - " %d %d \n", target_width, target_height); - return; - } - fclose(stand_alone_file); - - I420VideoFrame resampled_source_frame; - resampled_source_frame.CopyFrame(*out_frame); - - // Scale |resampled_source_frame| back to original/source size. - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(source_width, - source_height, - 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, - &out_frame)); - - // Write the processed frame to file for visual inspection. - std::ostringstream filename2; - filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << target_width << "x" << target_height << "_to_" << - source_width << "x" << source_height << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename2.str() << " and verify that it is okay." - << std::endl; - stand_alone_file = fopen(filename2.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height " - "%d %d \n", source_width, source_height); - return; - } - fclose(stand_alone_file); - - // Compute the PSNR and check expectation. - double psnr = I420PSNR(&source_frame, out_frame); - EXPECT_GT(psnr, expected_psnr); - printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " - "source which is scaled down/up to: %d %d, and back to source size \n", - psnr, source_width, source_height, target_width, target_height); - } -} - -bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2) { - for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { - webrtc::PlaneType plane_type = static_cast(plane); - int allocated_size1 = frame1.allocated_size(plane_type); - int allocated_size2 = frame2.allocated_size(plane_type); - if (allocated_size1 != allocated_size2) - return false; - const uint8_t* plane_buffer1 = frame1.buffer(plane_type); - const uint8_t* plane_buffer2 = frame2.buffer(plane_type); - if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) - return false; - } - return true; -} - -} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h b/webrtc/modules/video_processing/main/test/unit_test/unit_test.h deleted file mode 100644 index 62c40398b4..0000000000 --- a/webrtc/modules/video_processing/main/test/unit_test/unit_test.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H -#define WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H - -#include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/system_wrappers/interface/trace.h" -#include "webrtc/test/testsupport/fileutils.h" - -namespace webrtc { - -class VideoProcessingModuleTest : public ::testing::Test -{ -protected: - VideoProcessingModuleTest(); - virtual void SetUp(); - virtual void TearDown(); - static void SetUpTestCase() - { - Trace::CreateTrace(); - std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt"; - ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str())); - } - static void TearDownTestCase() - { - Trace::ReturnTrace(); - } - VideoProcessingModule* _vpm; - FILE* _sourceFile; - I420VideoFrame _videoFrame; - const int _width; - const int _half_width; - const int _height; - const int _size_y; - const int _size_uv; - const unsigned int _frame_length; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VPM_UNIT_TEST_H diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc new file mode 100644 index 0000000000..66452603c0 --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -0,0 +1,391 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" + +#include + +#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/fileutils.h" + +namespace webrtc { + +// The |sourceFrame| is scaled to |target_width|,|target_height|, using the +// filter mode set to |mode|. The |expected_psnr| is used to verify basic +// quality when the resampled frame is scaled back up/down to the +// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than +// actual PSNR verified under the same conditions. +void TestSize(const I420VideoFrame& sourceFrame, int target_width, + int target_height, int mode, double expected_psnr, + VideoProcessingModule* vpm); +bool CompareFrames(const webrtc::I420VideoFrame& frame1, + const webrtc::I420VideoFrame& frame2); + +VideoProcessingModuleTest::VideoProcessingModuleTest() : + _vpm(NULL), + _sourceFile(NULL), + _width(352), + _half_width((_width + 1) / 2), + _height(288), + _size_y(_width * _height), + _size_uv(_half_width * ((_height + 1) / 2)), + _frame_length(CalcBufferSize(kI420, _width, _height)) +{ +} + +void VideoProcessingModuleTest::SetUp() +{ + _vpm = VideoProcessingModule::Create(0); + ASSERT_TRUE(_vpm != NULL); + + ASSERT_EQ(0, _videoFrame.CreateEmptyFrame(_width, _height, _width, + _half_width, _half_width)); + + const std::string video_file = + webrtc::test::ResourcePath("foreman_cif", "yuv"); + _sourceFile = fopen(video_file.c_str(),"rb"); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read source file: " + video_file + "\n"; +} + +void VideoProcessingModuleTest::TearDown() +{ + if (_sourceFile != NULL) { + ASSERT_EQ(0, fclose(_sourceFile)); + } + _sourceFile = NULL; + + if (_vpm != NULL) { + VideoProcessingModule::Destroy(_vpm); + } + _vpm = NULL; +} + +TEST_F(VideoProcessingModuleTest, HandleNullBuffer) +{ + // TODO(mikhal/stefan): Do we need this one? + VideoProcessingModule::FrameStats stats; + // Video frame with unallocated buffer. + I420VideoFrame videoFrame; + videoFrame.set_width(_width); + videoFrame.set_height(_height); + + EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, videoFrame)); + + EXPECT_EQ(-1, _vpm->ColorEnhancement(&videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&videoFrame, &stats)); + + EXPECT_EQ(-1, _vpm->Denoising(&videoFrame)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats)); +} + +TEST_F(VideoProcessingModuleTest, HandleBadStats) +{ + VideoProcessingModule::FrameStats stats; + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); +} + +TEST_F(VideoProcessingModuleTest, HandleBadSize) +{ + VideoProcessingModule::FrameStats stats; + + _videoFrame.ResetSize(); + _videoFrame.set_width(_width); + _videoFrame.set_height(0); + EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); + + EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); + + EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + + EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); + + EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); + + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); + + I420VideoFrame *outFrame = NULL; + EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(_videoFrame, + &outFrame)); +} + +TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) +{ + I420VideoFrame videoFrame2; + VideoProcessingModule::FrameStats stats; + // Only testing non-static functions here. + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + ASSERT_EQ(0, videoFrame2.CopyFrame(_videoFrame)); + ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); + _vpm->Reset(); + // Retrieve frame stats again in case Deflickering() has zeroed them. + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, videoFrame2)); + ASSERT_EQ(0, _vpm->Deflickering(&videoFrame2, &stats)); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + videoFrame2.CopyFrame(_videoFrame); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); + _vpm->Reset(); + ASSERT_GE(_vpm->Denoising(&videoFrame2), 0); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + videoFrame2.CopyFrame(_videoFrame); + ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); + _vpm->Reset(); + ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); + EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); +} + +TEST_F(VideoProcessingModuleTest, FrameStats) +{ + VideoProcessingModule::FrameStats stats; + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + + EXPECT_FALSE(_vpm->ValidFrameStats(stats)); + EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); + EXPECT_TRUE(_vpm->ValidFrameStats(stats)); + + printf("\nFrameStats\n"); + printf("mean: %u\nnumPixels: %u\nsubSamplWidth: " + "%u\nsumSamplHeight: %u\nsum: %u\n\n", + static_cast(stats.mean), + static_cast(stats.numPixels), + static_cast(stats.subSamplHeight), + static_cast(stats.subSamplWidth), + static_cast(stats.sum)); + + _vpm->ClearFrameStats(&stats); + EXPECT_FALSE(_vpm->ValidFrameStats(stats)); +} + +TEST_F(VideoProcessingModuleTest, PreprocessorLogic) +{ + // Disable temporal sampling (frame dropping). + _vpm->EnableTemporalDecimation(false); + int resolution = 100; + EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + // Disable spatial sampling. + _vpm->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + I420VideoFrame* outFrame = NULL; + // Set rescaling => output frame != NULL. + _vpm->SetInputFrameResampleMode(kFastRescaling); + EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_FALSE(outFrame == NULL); + if (outFrame) { + EXPECT_EQ(resolution, outFrame->width()); + EXPECT_EQ(resolution, outFrame->height()); + } + // No rescaling=> output frame = NULL. + _vpm->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); + EXPECT_TRUE(outFrame == NULL); +} + +TEST_F(VideoProcessingModuleTest, Resampler) +{ + enum { NumRuns = 1 }; + + int64_t minRuntime = 0; + int64_t avgRuntime = 0; + + TickTime t0; + TickTime t1; + TickInterval accTicks; + + rewind(_sourceFile); + ASSERT_TRUE(_sourceFile != NULL) << + "Cannot read input file \n"; + + // CA not needed here + _vpm->EnableContentAnalysis(false); + // no temporal decimation + _vpm->EnableTemporalDecimation(false); + + // Reading test frame + scoped_array video_buffer(new uint8_t[_frame_length]); + ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, + _sourceFile)); + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + _width, _height, + 0, kRotateNone, &_videoFrame)); + + for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) + { + // initiate test timer + t0 = TickTime::Now(); + + // Init the sourceFrame with a timestamp. + _videoFrame.set_render_time_ms(t0.MillisecondTimestamp()); + _videoFrame.set_timestamp(t0.MillisecondTimestamp() * 90); + + // Test scaling to different sizes: source is of |width|/|height| = 352/288. + // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). + TestSize(_videoFrame, 100, 50, 3, 24.0, _vpm); + TestSize(_videoFrame, 352/4, 288/4, 3, 25.2, _vpm); + TestSize(_videoFrame, 352/2, 288/2, 3, 28.1, _vpm); + TestSize(_videoFrame, 352, 288, 3, -1, _vpm); // no resampling. + TestSize(_videoFrame, 2*352, 2*288, 3, 32.2, _vpm); + TestSize(_videoFrame, 400, 256, 3, 31.3, _vpm); + TestSize(_videoFrame, 480, 640, 3, 32.15, _vpm); + TestSize(_videoFrame, 960, 720, 3, 32.2, _vpm); + TestSize(_videoFrame, 1280, 720, 3, 32.15, _vpm); + // Upsampling to odd size. + TestSize(_videoFrame, 501, 333, 3, 32.05, _vpm); + // Downsample to odd size. + TestSize(_videoFrame, 281, 175, 3, 29.3, _vpm); + + // stop timer + t1 = TickTime::Now(); + accTicks += (t1 - t0); + + if (accTicks.Microseconds() < minRuntime || runIdx == 0) { + minRuntime = accTicks.Microseconds(); + } + avgRuntime += accTicks.Microseconds(); + } + + printf("\nAverage run time = %d us / frame\n", + //static_cast(avgRuntime / frameNum / NumRuns)); + static_cast(avgRuntime)); + printf("Min run time = %d us / frame\n\n", + //static_cast(minRuntime / frameNum)); + static_cast(minRuntime)); +} + +void TestSize(const I420VideoFrame& source_frame, int target_width, + int target_height, int mode, double expected_psnr, + VideoProcessingModule* vpm) { + int source_width = source_frame.width(); + int source_height = source_frame.height(); + I420VideoFrame* out_frame = NULL; + + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); + + if (out_frame) { + EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); + EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); + } + + // If the frame was resampled (scale changed) then: + // (1) verify the new size and write out processed frame for viewing. + // (2) scale the resampled frame (|out_frame|) back to the original size and + // compute PSNR relative to |source_frame| (for automatic verification). + // (3) write out the processed frame for viewing. + if (target_width != static_cast(source_width) || + target_height != static_cast(source_height)) { + // Write the processed frame to file for visual inspection. + std::ostringstream filename; + filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << source_width << "x" << source_height << "_to_" << + target_width << "x" << target_height << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename.str() << " and verify that it is okay." + << std::endl; + FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { + fprintf(stderr, "Failed to write frame for scaling to width/height: " + " %d %d \n", target_width, target_height); + return; + } + fclose(stand_alone_file); + + I420VideoFrame resampled_source_frame; + resampled_source_frame.CopyFrame(*out_frame); + + // Scale |resampled_source_frame| back to original/source size. + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(source_width, + source_height, + 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, + &out_frame)); + + // Write the processed frame to file for visual inspection. + std::ostringstream filename2; + filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << target_width << "x" << target_height << "_to_" << + source_width << "x" << source_height << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename2.str() << " and verify that it is okay." + << std::endl; + stand_alone_file = fopen(filename2.str().c_str(), "wb"); + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { + fprintf(stderr, "Failed to write frame for scaling to width/height " + "%d %d \n", source_width, source_height); + return; + } + fclose(stand_alone_file); + + // Compute the PSNR and check expectation. + double psnr = I420PSNR(&source_frame, out_frame); + EXPECT_GT(psnr, expected_psnr); + printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " + "source which is scaled down/up to: %d %d, and back to source size \n", + psnr, source_width, source_height, target_width, target_height); + } +} + +bool CompareFrames(const webrtc::I420VideoFrame& frame1, + const webrtc::I420VideoFrame& frame2) { + for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { + webrtc::PlaneType plane_type = static_cast(plane); + int allocated_size1 = frame1.allocated_size(plane_type); + int allocated_size2 = frame2.allocated_size(plane_type); + if (allocated_size1 != allocated_size2) + return false; + const uint8_t* plane_buffer1 = frame1.buffer(plane_type); + const uint8_t* plane_buffer2 = frame2.buffer(plane_type); + if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) + return false; + } + return true; +} + +} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h new file mode 100644 index 0000000000..db8841b5da --- /dev/null +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VIDEO_PROCESSING_UNITTEST_H +#define WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VIDEO_PROCESSING_UNITTEST_H + +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/modules/video_processing/main/interface/video_processing.h" +#include "webrtc/system_wrappers/interface/trace.h" +#include "webrtc/test/testsupport/fileutils.h" + +namespace webrtc { + +class VideoProcessingModuleTest : public ::testing::Test +{ +protected: + VideoProcessingModuleTest(); + virtual void SetUp(); + virtual void TearDown(); + static void SetUpTestCase() + { + Trace::CreateTrace(); + std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt"; + ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str())); + } + static void TearDownTestCase() + { + Trace::ReturnTrace(); + } + VideoProcessingModule* _vpm; + FILE* _sourceFile; + I420VideoFrame _videoFrame; + const int _width; + const int _half_width; + const int _height; + const int _size_y; + const int _size_uv; + const unsigned int _frame_length; +}; + +} // namespace webrtc + +#endif // WEBRTC_MODULES_VIDEO_PROCESSING_MAIN_TEST_UNIT_TEST_VIDEO_PROCESSING_UNITTEST_H -- cgit v1.2.3 From a950300b0ef20289d44e7f81b8709fa7bc2be6e6 Mon Sep 17 00:00:00 2001 From: "henrike@webrtc.org" Date: Mon, 8 Jul 2013 18:53:54 +0000 Subject: Disables unit tests that don't work on Android for Android. BUG=N/A R=andrew@webrtc.org, kjellander@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1747004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4306 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 71d133bdfc..8c47917771 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -16,10 +16,11 @@ #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" +#include "webrtc/test/testsupport/gtest_disable.h" namespace webrtc { -TEST_F(VideoProcessingModuleTest, Denoising) +TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) { enum { NumRuns = 10 }; uint32_t frameNum = 0; -- cgit v1.2.3 From 12dc1a38ca54a000e4fecfbc6d41138b895c9ca5 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Mon, 5 Aug 2013 16:22:53 +0000 Subject: Switch C++-style C headers with their C equivalents. The C++ headers define the C functions within the std:: namespace, but we mainly don't use the std:: namespace for C functions. Therefore we should include the C headers. BUG=1833 R=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1917004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4486 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_processing/main/test/unit_test/color_enhancement_test.cc | 4 ++-- .../modules/video_processing/main/test/unit_test/deflickering_test.cc | 4 ++-- webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index ea1ed41c49..c048003fb9 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include -#include +#include +#include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 48afcf569d..85f4fd6ebb 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include -#include +#include +#include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 8c47917771..8a3439318b 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include -#include +#include +#include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -- cgit v1.2.3 From b43d8078a152d91037b25175712a57a9a377220a Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Thu, 3 Oct 2013 16:42:41 +0000 Subject: Reformatting VPM: First step - No functional changes. R=marpan@google.com, marpan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2333004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4912 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 56 ++-- .../main/test/unit_test/color_enhancement_test.cc | 76 ++--- .../main/test/unit_test/content_metrics_test.cc | 44 ++- .../main/test/unit_test/deflickering_test.cc | 56 ++-- .../main/test/unit_test/denoising_test.cc | 66 ++-- .../test/unit_test/video_processing_unittest.cc | 360 ++++++++++----------- .../test/unit_test/video_processing_unittest.h | 47 ++- 7 files changed, 344 insertions(+), 361 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index d17ade9696..d7ac72908a 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -19,24 +19,24 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) uint32_t frameNum = 0; int32_t brightnessWarning = 0; uint32_t warningCount = 0; - scoped_array video_buffer(new uint8_t[_frame_length]); - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length) + scoped_array video_buffer(new uint8_t[frame_length_]); + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); frameNum++; VideoProcessingModule::FrameStats stats; - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, stats), 0); if (brightnessWarning != VideoProcessingModule::kNoWarning) { warningCount++; } } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; // Expect few warnings float warningProportion = static_cast(warningCount) / frameNum * 100; @@ -44,21 +44,21 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) printf("Stock foreman: %.1f %%\n", warningProportion); EXPECT_LT(warningProportion, 10); - rewind(_sourceFile); + rewind(source_file_); frameNum = 0; warningCount = 0; - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length && + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_ && frameNum < 300) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); frameNum++; - uint8_t* frame = _videoFrame.buffer(kYPlane); + uint8_t* frame = video_frame_.buffer(kYPlane); uint32_t yTmp = 0; - for (int yIdx = 0; yIdx < _width * _height; yIdx++) + for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { yTmp = frame[yIdx] << 1; if (yTmp > 255) @@ -69,8 +69,8 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) } VideoProcessingModule::FrameStats stats; - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, stats), 0); EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning); if (brightnessWarning == VideoProcessingModule::kBrightWarning) @@ -78,35 +78,35 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) warningCount++; } } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; // Expect many brightness warnings warningProportion = static_cast(warningCount) / frameNum * 100; printf("Bright foreman: %.1f %%\n", warningProportion); EXPECT_GT(warningProportion, 95); - rewind(_sourceFile); + rewind(source_file_); frameNum = 0; warningCount = 0; - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length && frameNum < 300) + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_ && frameNum < 300) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); frameNum++; - uint8_t* y_plane = _videoFrame.buffer(kYPlane); + uint8_t* y_plane = video_frame_.buffer(kYPlane); int32_t yTmp = 0; - for (int yIdx = 0; yIdx < _width * _height; yIdx++) + for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { yTmp = y_plane[yIdx] >> 1; y_plane[yIdx] = static_cast(yTmp); } VideoProcessingModule::FrameStats stats; - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_GE(brightnessWarning = _vpm->BrightnessDetection(_videoFrame, + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, stats), 0); EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning); if (brightnessWarning == VideoProcessingModule::kDarkWarning) @@ -114,7 +114,7 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) warningCount++; } } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; // Expect many darkness warnings warningProportion = static_cast(warningCount) / frameNum * 100; diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index c048003fb9..fc560bef13 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -23,14 +23,14 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) { TickTime t0; TickTime t1; - TickInterval accTicks; + TickInterval acc_ticks; // Use a shorter version of the Foreman clip for this test. - fclose(_sourceFile); + fclose(source_file_); const std::string video_file = webrtc::test::ResourcePath("foreman_cif_short", "yuv"); - _sourceFile = fopen(video_file.c_str(), "rb"); - ASSERT_TRUE(_sourceFile != NULL) << + source_file_ = fopen(video_file.c_str(), "rb"); + ASSERT_TRUE(source_file_ != NULL) << "Cannot read source file: " + video_file + "\n"; std::string output_file = webrtc::test::OutputPath() + @@ -39,27 +39,27 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; uint32_t frameNum = 0; - scoped_array video_buffer(new uint8_t[_frame_length]); - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length) + scoped_array video_buffer(new uint8_t[frame_length_]); + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_) { // Using ConvertToI420 to add stride to the image. EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); frameNum++; t0 = TickTime::Now(); - ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&_videoFrame)); + ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&video_frame_)); t1 = TickTime::Now(); - accTicks += t1 - t0; - if (PrintI420VideoFrame(_videoFrame, modFile) < 0) { + acc_ticks += t1 - t0; + if (PrintI420VideoFrame(video_frame_, modFile) < 0) { return; } } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; printf("\nTime per frame: %d us \n", - static_cast(accTicks.Microseconds() / frameNum)); + static_cast(acc_ticks.Microseconds() / frameNum)); rewind(modFile); printf("Comparing files...\n\n"); @@ -82,62 +82,62 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_EQ(refLen, testLen) << "File lengths differ."; I420VideoFrame refVideoFrame; - refVideoFrame.CreateEmptyFrame(_width, _height, - _width, _half_width, _half_width); + refVideoFrame.CreateEmptyFrame(width_, height_, + width_, half_width_, half_width_); // Compare frame-by-frame. - scoped_array ref_buffer(new uint8_t[_frame_length]); - while (fread(video_buffer.get(), 1, _frame_length, modFile) == - _frame_length) + scoped_array ref_buffer(new uint8_t[frame_length_]); + while (fread(video_buffer.get(), 1, frame_length_, modFile) == + frame_length_) { // Using ConvertToI420 to add stride to the image. EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - ASSERT_EQ(_frame_length, fread(ref_buffer.get(), 1, _frame_length, + width_, height_, + 0, kRotateNone, &video_frame_)); + ASSERT_EQ(frame_length_, fread(ref_buffer.get(), 1, frame_length_, refFile)); EXPECT_EQ(0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, - _width, _height, + width_, height_, 0, kRotateNone, &refVideoFrame)); - EXPECT_EQ(0, memcmp(_videoFrame.buffer(kYPlane), + EXPECT_EQ(0, memcmp(video_frame_.buffer(kYPlane), refVideoFrame.buffer(kYPlane), - _size_y)); - EXPECT_EQ(0, memcmp(_videoFrame.buffer(kUPlane), + size_y_)); + EXPECT_EQ(0, memcmp(video_frame_.buffer(kUPlane), refVideoFrame.buffer(kUPlane), - _size_uv)); - EXPECT_EQ(0, memcmp(_videoFrame.buffer(kVPlane), + size_uv_)); + EXPECT_EQ(0, memcmp(video_frame_.buffer(kVPlane), refVideoFrame.buffer(kVPlane), - _size_uv)); + size_uv_)); } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; // Verify that all color pixels are enhanced, and no luminance values are // altered. - scoped_array testFrame(new uint8_t[_frame_length]); + scoped_array testFrame(new uint8_t[frame_length_]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. - memset(testFrame.get(), 128, _frame_length); + memset(testFrame.get(), 128, frame_length_); I420VideoFrame testVideoFrame; - testVideoFrame.CreateEmptyFrame(_width, _height, - _width, _half_width, _half_width); + testVideoFrame.CreateEmptyFrame(width_, height_, + width_, half_width_, half_width_); EXPECT_EQ(0, ConvertToI420(kI420, testFrame.get(), 0, 0, - _width, _height, 0, kRotateNone, + width_, height_, 0, kRotateNone, &testVideoFrame)); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); EXPECT_EQ(0, memcmp(testVideoFrame.buffer(kYPlane), testFrame.get(), - _size_y)) + size_y_)) << "Function is modifying the luminance."; EXPECT_NE(0, memcmp(testVideoFrame.buffer(kUPlane), - testFrame.get() + _size_y, _size_uv)) << + testFrame.get() + size_y_, size_uv_)) << "Function is not modifying all chrominance pixels"; EXPECT_NE(0, memcmp(testVideoFrame.buffer(kVPlane), - testFrame.get() + _size_y + _size_uv, _size_uv)) << + testFrame.get() + size_y_ + size_uv_, size_uv_)) << "Function is not modifying all chrominance pixels"; ASSERT_EQ(0, fclose(refFile)); diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 26080da784..36a1ad7625 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -15,32 +15,30 @@ namespace webrtc { -TEST_F(VideoProcessingModuleTest, ContentAnalysis) -{ - VPMContentAnalysis _ca_c(false); - VPMContentAnalysis _ca_sse(true); - VideoContentMetrics *_cM_c, *_cM_SSE; +TEST_F(VideoProcessingModuleTest, ContentAnalysis) { + VPMContentAnalysis ca__c(false); + VPMContentAnalysis ca__sse(true); + VideoContentMetrics *_cM_c, *_cM_SSE; - _ca_c.Initialize(_width,_height); - _ca_sse.Initialize(_width,_height); + ca__c.Initialize(width_,height_); + ca__sse.Initialize(width_,height_); - scoped_array video_buffer(new uint8_t[_frame_length]); - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) - == _frame_length) - { - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - _cM_c = _ca_c.ComputeContentMetrics(_videoFrame); - _cM_SSE = _ca_sse.ComputeContentMetrics(_videoFrame); + scoped_array video_buffer(new uint8_t[frame_length_]); + while (fread(video_buffer.get(), 1, frame_length_, source_file_) + == frame_length_) { + // Using ConvertToI420 to add stride to the image. + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, + width_, height_, + 0, kRotateNone, &video_frame_)); + _cM_c = ca__c.ComputeContentMetrics(video_frame_); + _cM_SSE = ca__sse.ComputeContentMetrics(video_frame_); - ASSERT_EQ(_cM_c->spatial_pred_err, _cM_SSE->spatial_pred_err); - ASSERT_EQ(_cM_c->spatial_pred_err_v, _cM_SSE->spatial_pred_err_v); - ASSERT_EQ(_cM_c->spatial_pred_err_h, _cM_SSE->spatial_pred_err_h); - ASSERT_EQ(_cM_c->motion_magnitude, _cM_SSE->motion_magnitude); - } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_EQ(_cM_c->spatial_pred_err, _cM_SSE->spatial_pred_err); + ASSERT_EQ(_cM_c->spatial_pred_err_v, _cM_SSE->spatial_pred_err_v); + ASSERT_EQ(_cM_c->spatial_pred_err_h, _cM_SSE->spatial_pred_err_h); + ASSERT_EQ(_cM_c->motion_magnitude, _cM_SSE->motion_magnitude); + } + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; } } // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 85f4fd6ebb..0fa3f48b4f 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -23,17 +23,17 @@ TEST_F(VideoProcessingModuleTest, Deflickering) { enum { NumRuns = 30 }; uint32_t frameNum = 0; - const uint32_t frameRate = 15; + const uint32_t frame_rate = 15; - int64_t minRuntime = 0; - int64_t avgRuntime = 0; + int64_t min_runtime = 0; + int64_t avg_runtime = 0; // Close automatically opened Foreman. - fclose(_sourceFile); + fclose(source_file_); const std::string input_file = webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv"); - _sourceFile = fopen(input_file.c_str(), "rb"); - ASSERT_TRUE(_sourceFile != NULL) << + source_file_ = fopen(input_file.c_str(), "rb"); + ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file: " << input_file << "\n"; const std::string output_file = @@ -43,57 +43,57 @@ TEST_F(VideoProcessingModuleTest, Deflickering) "Could not open output file: " << output_file << "\n"; printf("\nRun time [us / frame]:\n"); - scoped_array video_buffer(new uint8_t[_frame_length]); - for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) + scoped_array video_buffer(new uint8_t[frame_length_]); + for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { TickTime t0; TickTime t1; - TickInterval accTicks; + TickInterval acc_ticks; uint32_t timeStamp = 1; frameNum = 0; - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length) + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_) { frameNum++; EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - _videoFrame.set_timestamp(timeStamp); + width_, height_, + 0, kRotateNone, &video_frame_)); + video_frame_.set_timestamp(timeStamp); t0 = TickTime::Now(); VideoProcessingModule::FrameStats stats; - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats)); t1 = TickTime::Now(); - accTicks += (t1 - t0); + acc_ticks += (t1 - t0); - if (runIdx == 0) + if (run_idx == 0) { - if (PrintI420VideoFrame(_videoFrame, deflickerFile) < 0) { + if (PrintI420VideoFrame(video_frame_, deflickerFile) < 0) { return; } } - timeStamp += (90000 / frameRate); + timeStamp += (90000 / frame_rate); } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; - printf("%u\n", static_cast(accTicks.Microseconds() / frameNum)); - if (accTicks.Microseconds() < minRuntime || runIdx == 0) + printf("%u\n", static_cast(acc_ticks.Microseconds() / frameNum)); + if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { - minRuntime = accTicks.Microseconds(); + min_runtime = acc_ticks.Microseconds(); } - avgRuntime += accTicks.Microseconds(); + avg_runtime += acc_ticks.Microseconds(); - rewind(_sourceFile); + rewind(source_file_); } ASSERT_EQ(0, fclose(deflickerFile)); // TODO(kjellander): Add verification of deflicker output file. printf("\nAverage run time = %d us / frame\n", - static_cast(avgRuntime / frameNum / NumRuns)); + static_cast(avg_runtime / frameNum / NumRuns)); printf("Min run time = %d us / frame\n\n", - static_cast(minRuntime / frameNum)); + static_cast(min_runtime / frameNum)); } } // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 8a3439318b..3023a2d7af 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -25,8 +25,8 @@ TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) enum { NumRuns = 10 }; uint32_t frameNum = 0; - int64_t minRuntime = 0; - int64_t avgRuntime = 0; + int64_t min_runtime = 0; + int64_t avg_runtime = 0; const std::string denoise_filename = webrtc::test::OutputPath() + "denoise_testfile.yuv"; @@ -41,50 +41,50 @@ TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) "Could not open noisy file: " << noise_filename << "\n"; printf("\nRun time [us / frame]:\n"); - for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) + for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { TickTime t0; TickTime t1; - TickInterval accTicks; + TickInterval acc_ticks; int32_t modifiedPixels = 0; frameNum = 0; - scoped_array video_buffer(new uint8_t[_frame_length]); - while (fread(video_buffer.get(), 1, _frame_length, _sourceFile) == - _frame_length) + scoped_array video_buffer(new uint8_t[frame_length_]); + while (fread(video_buffer.get(), 1, frame_length_, source_file_) == + frame_length_) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); frameNum++; - uint8_t* sourceBuffer = _videoFrame.buffer(kYPlane); + uint8_t* sourceBuffer = video_frame_.buffer(kYPlane); // Add noise to a part in video stream // Random noise // TODO: investigate the effectiveness of this test. - for (int ir = 0; ir < _height; ir++) + for (int ir = 0; ir < height_; ir++) { - uint32_t ik = ir * _width; - for (int ic = 0; ic < _width; ic++) + uint32_t ik = ir * width_; + for (int ic = 0; ic < width_; ic++) { uint8_t r = rand() % 16; r -= 8; - if (ir < _height / 4) + if (ir < height_ / 4) r = 0; - if (ir >= 3 * _height / 4) + if (ir >= 3 * height_ / 4) r = 0; - if (ic < _width / 4) + if (ic < width_ / 4) r = 0; - if (ic >= 3 * _width / 4) + if (ic >= 3 * width_ / 4) r = 0; /*uint8_t pixelValue = 0; - if (ir >= _height / 2) + if (ir >= height_ / 2) { // Region 3 or 4 pixelValue = 170; } - if (ic >= _width / 2) + if (ic >= width_ / 2) { // Region 2 or 4 pixelValue += 85; } @@ -95,42 +95,42 @@ TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) } } - if (runIdx == 0) + if (run_idx == 0) { - if (PrintI420VideoFrame(_videoFrame, noiseFile) < 0) { + if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { return; } } t0 = TickTime::Now(); - ASSERT_GE(modifiedPixels = _vpm->Denoising(&_videoFrame), 0); + ASSERT_GE(modifiedPixels = vpm_->Denoising(&video_frame_), 0); t1 = TickTime::Now(); - accTicks += (t1 - t0); + acc_ticks += (t1 - t0); - if (runIdx == 0) + if (run_idx == 0) { - if (PrintI420VideoFrame(_videoFrame, noiseFile) < 0) { + if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { return; } } } - ASSERT_NE(0, feof(_sourceFile)) << "Error reading source file"; + ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; - printf("%u\n", static_cast(accTicks.Microseconds() / frameNum)); - if (accTicks.Microseconds() < minRuntime || runIdx == 0) + printf("%u\n", static_cast(acc_ticks.Microseconds() / frameNum)); + if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { - minRuntime = accTicks.Microseconds(); + min_runtime = acc_ticks.Microseconds(); } - avgRuntime += accTicks.Microseconds(); + avg_runtime += acc_ticks.Microseconds(); - rewind(_sourceFile); + rewind(source_file_); } ASSERT_EQ(0, fclose(denoiseFile)); ASSERT_EQ(0, fclose(noiseFile)); printf("\nAverage run time = %d us / frame\n", - static_cast(avgRuntime / frameNum / NumRuns)); + static_cast(avg_runtime / frameNum / NumRuns)); printf("Min run time = %d us / frame\n\n", - static_cast(minRuntime / frameNum)); + static_cast(min_runtime / frameNum)); } } // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 66452603c0..89c59ec8b1 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -18,297 +18,285 @@ namespace webrtc { -// The |sourceFrame| is scaled to |target_width|,|target_height|, using the +// The |sourceFrame| is scaled to |targetwidth_|,|targetheight_|, using the // filter mode set to |mode|. The |expected_psnr| is used to verify basic // quality when the resampled frame is scaled back up/down to the // original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than // actual PSNR verified under the same conditions. -void TestSize(const I420VideoFrame& sourceFrame, int target_width, - int target_height, int mode, double expected_psnr, +void TestSize(const I420VideoFrame& sourceFrame, int targetwidth_, + int targetheight_, int mode, double expected_psnr, VideoProcessingModule* vpm); bool CompareFrames(const webrtc::I420VideoFrame& frame1, const webrtc::I420VideoFrame& frame2); -VideoProcessingModuleTest::VideoProcessingModuleTest() : - _vpm(NULL), - _sourceFile(NULL), - _width(352), - _half_width((_width + 1) / 2), - _height(288), - _size_y(_width * _height), - _size_uv(_half_width * ((_height + 1) / 2)), - _frame_length(CalcBufferSize(kI420, _width, _height)) -{ -} +VideoProcessingModuleTest::VideoProcessingModuleTest() + : vpm_(NULL), + source_file_(NULL), + width_(352), + half_width_((width_ + 1) / 2), + height_(288), + size_y_(width_ * height_), + size_uv_(half_width_ * ((height_ + 1) / 2)), + frame_length_(CalcBufferSize(kI420, width_, height_)) {} -void VideoProcessingModuleTest::SetUp() -{ - _vpm = VideoProcessingModule::Create(0); - ASSERT_TRUE(_vpm != NULL); +void VideoProcessingModuleTest::SetUp() { + vpm_ = VideoProcessingModule::Create(0); + ASSERT_TRUE(vpm_ != NULL); - ASSERT_EQ(0, _videoFrame.CreateEmptyFrame(_width, _height, _width, - _half_width, _half_width)); + ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, + half_width_, half_width_)); const std::string video_file = webrtc::test::ResourcePath("foreman_cif", "yuv"); - _sourceFile = fopen(video_file.c_str(),"rb"); - ASSERT_TRUE(_sourceFile != NULL) << + source_file_ = fopen(video_file.c_str(),"rb"); + ASSERT_TRUE(source_file_ != NULL) << "Cannot read source file: " + video_file + "\n"; } -void VideoProcessingModuleTest::TearDown() -{ - if (_sourceFile != NULL) { - ASSERT_EQ(0, fclose(_sourceFile)); +void VideoProcessingModuleTest::TearDown() { + if (source_file_ != NULL) { + ASSERT_EQ(0, fclose(source_file_)); } - _sourceFile = NULL; + source_file_ = NULL; - if (_vpm != NULL) { - VideoProcessingModule::Destroy(_vpm); + if (vpm_ != NULL) { + VideoProcessingModule::Destroy(vpm_); } - _vpm = NULL; + vpm_ = NULL; } -TEST_F(VideoProcessingModuleTest, HandleNullBuffer) -{ +TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { // TODO(mikhal/stefan): Do we need this one? VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. I420VideoFrame videoFrame; - videoFrame.set_width(_width); - videoFrame.set_height(_height); + videoFrame.set_width(width_); + videoFrame.set_height(height_); - EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, videoFrame)); + EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); - EXPECT_EQ(-1, _vpm->ColorEnhancement(&videoFrame)); + EXPECT_EQ(-1, vpm_->ColorEnhancement(&videoFrame)); - EXPECT_EQ(-1, _vpm->Deflickering(&videoFrame, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&videoFrame, &stats)); - EXPECT_EQ(-1, _vpm->Denoising(&videoFrame)); + EXPECT_EQ(-1, vpm_->Denoising(&videoFrame)); - EXPECT_EQ(-3, _vpm->BrightnessDetection(videoFrame, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(videoFrame, stats)); } -TEST_F(VideoProcessingModuleTest, HandleBadStats) -{ +TEST_F(VideoProcessingModuleTest, HandleBadStats) { VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + scoped_array video_buffer(new uint8_t[frame_length_]); + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); - EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); - EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); } -TEST_F(VideoProcessingModuleTest, HandleBadSize) -{ +TEST_F(VideoProcessingModuleTest, HandleBadSize) { VideoProcessingModule::FrameStats stats; - _videoFrame.ResetSize(); - _videoFrame.set_width(_width); - _videoFrame.set_height(0); - EXPECT_EQ(-3, _vpm->GetFrameStats(&stats, _videoFrame)); + video_frame_.ResetSize(); + video_frame_.set_width(width_); + video_frame_.set_height(0); + EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, video_frame_)); - EXPECT_EQ(-1, _vpm->ColorEnhancement(&_videoFrame)); + EXPECT_EQ(-1, vpm_->ColorEnhancement(&video_frame_)); - EXPECT_EQ(-1, _vpm->Deflickering(&_videoFrame, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); - EXPECT_EQ(-1, _vpm->Denoising(&_videoFrame)); + EXPECT_EQ(-1, vpm_->Denoising(&video_frame_)); - EXPECT_EQ(-3, _vpm->BrightnessDetection(_videoFrame, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetTargetResolution(0,0,0)); - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->SetMaxFrameRate(0)); + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetMaxFramerate(0)); - I420VideoFrame *outFrame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, _vpm->PreprocessFrame(_videoFrame, - &outFrame)); + I420VideoFrame *out_frame = NULL; + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(video_frame_, + &out_frame)); } -TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) -{ - I420VideoFrame videoFrame2; +TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { + I420VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + scoped_array video_buffer(new uint8_t[frame_length_]); + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - ASSERT_EQ(0, videoFrame2.CopyFrame(_videoFrame)); - ASSERT_EQ(0, _vpm->Deflickering(&_videoFrame, &stats)); - _vpm->Reset(); + width_, height_, + 0, kRotateNone, &video_frame_)); + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_)); + ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats)); + vpm_->Reset(); // Retrieve frame stats again in case Deflickering() has zeroed them. - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, videoFrame2)); - ASSERT_EQ(0, _vpm->Deflickering(&videoFrame2, &stats)); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame2)); + ASSERT_EQ(0, vpm_->Deflickering(&video_frame2, &stats)); + EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); // Using ConvertToI420 to add stride to the image. EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - videoFrame2.CopyFrame(_videoFrame); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); - ASSERT_GE(_vpm->Denoising(&_videoFrame), 0); - _vpm->Reset(); - ASSERT_GE(_vpm->Denoising(&videoFrame2), 0); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); - - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + width_, height_, + 0, kRotateNone, &video_frame_)); + video_frame2.CopyFrame(video_frame_); + EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); + ASSERT_GE(vpm_->Denoising(&video_frame_), 0); + vpm_->Reset(); + ASSERT_GE(vpm_->Denoising(&video_frame2), 0); + EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); + + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); - ASSERT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - videoFrame2.CopyFrame(_videoFrame); - ASSERT_EQ(0, _vpm->BrightnessDetection(_videoFrame, stats)); - _vpm->Reset(); - ASSERT_EQ(0, _vpm->BrightnessDetection(videoFrame2, stats)); - EXPECT_TRUE(CompareFrames(_videoFrame, videoFrame2)); + width_, height_, + 0, kRotateNone, &video_frame_)); + ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + video_frame2.CopyFrame(video_frame_); + ASSERT_EQ(0, vpm_->BrightnessDetection(video_frame_, stats)); + vpm_->Reset(); + ASSERT_EQ(0, vpm_->BrightnessDetection(video_frame2, stats)); + EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); } -TEST_F(VideoProcessingModuleTest, FrameStats) -{ +TEST_F(VideoProcessingModuleTest, FrameStats) { VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + scoped_array video_buffer(new uint8_t[frame_length_]); + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); - EXPECT_FALSE(_vpm->ValidFrameStats(stats)); - EXPECT_EQ(0, _vpm->GetFrameStats(&stats, _videoFrame)); - EXPECT_TRUE(_vpm->ValidFrameStats(stats)); + EXPECT_FALSE(vpm_->ValidFrameStats(stats)); + EXPECT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); + EXPECT_TRUE(vpm_->ValidFrameStats(stats)); printf("\nFrameStats\n"); - printf("mean: %u\nnumPixels: %u\nsubSamplWidth: " + printf("mean: %u\nnum_pixels: %u\nsubSamplWidth: " "%u\nsumSamplHeight: %u\nsum: %u\n\n", static_cast(stats.mean), - static_cast(stats.numPixels), + static_cast(stats.num_pixels), static_cast(stats.subSamplHeight), static_cast(stats.subSamplWidth), static_cast(stats.sum)); - _vpm->ClearFrameStats(&stats); - EXPECT_FALSE(_vpm->ValidFrameStats(stats)); + vpm_->ClearFrameStats(&stats); + EXPECT_FALSE(vpm_->ValidFrameStats(stats)); } -TEST_F(VideoProcessingModuleTest, PreprocessorLogic) -{ +TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { // Disable temporal sampling (frame dropping). - _vpm->EnableTemporalDecimation(false); + vpm_->EnableTemporalDecimation(false); int resolution = 100; - EXPECT_EQ(VPM_OK, _vpm->SetMaxFrameRate(30)); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 15)); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, vpm_->SetMaxFramerate(30)); + EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 15)); + EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); // Disable spatial sampling. - _vpm->SetInputFrameResampleMode(kNoRescaling); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); - I420VideoFrame* outFrame = NULL; + vpm_->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); + I420VideoFrame* out_frame = NULL; // Set rescaling => output frame != NULL. - _vpm->SetInputFrameResampleMode(kFastRescaling); - EXPECT_EQ(VPM_OK, _vpm->SetTargetResolution(resolution, resolution, 30)); - EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - EXPECT_FALSE(outFrame == NULL); - if (outFrame) { - EXPECT_EQ(resolution, outFrame->width()); - EXPECT_EQ(resolution, outFrame->height()); + vpm_->SetInputFrameResampleMode(kFastRescaling); + EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); + EXPECT_FALSE(out_frame == NULL); + if (out_frame) { + EXPECT_EQ(resolution, out_frame->width()); + EXPECT_EQ(resolution, out_frame->height()); } // No rescaling=> output frame = NULL. - _vpm->SetInputFrameResampleMode(kNoRescaling); - EXPECT_EQ(VPM_OK, _vpm->PreprocessFrame(_videoFrame, &outFrame)); - EXPECT_TRUE(outFrame == NULL); + vpm_->SetInputFrameResampleMode(kNoRescaling); + EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); + EXPECT_TRUE(out_frame == NULL); } -TEST_F(VideoProcessingModuleTest, Resampler) -{ +TEST_F(VideoProcessingModuleTest, Resampler) { enum { NumRuns = 1 }; - int64_t minRuntime = 0; - int64_t avgRuntime = 0; + int64_t min_runtime = 0; + int64_t avg_runtime = 0; TickTime t0; TickTime t1; - TickInterval accTicks; + TickInterval acc_ticks; - rewind(_sourceFile); - ASSERT_TRUE(_sourceFile != NULL) << + rewind(source_file_); + ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file \n"; // CA not needed here - _vpm->EnableContentAnalysis(false); + vpm_->EnableContentAnalysis(false); // no temporal decimation - _vpm->EnableTemporalDecimation(false); + vpm_->EnableTemporalDecimation(false); // Reading test frame - scoped_array video_buffer(new uint8_t[_frame_length]); - ASSERT_EQ(_frame_length, fread(video_buffer.get(), 1, _frame_length, - _sourceFile)); + scoped_array video_buffer(new uint8_t[frame_length_]); + ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, + source_file_)); // Using ConvertToI420 to add stride to the image. EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - _width, _height, - 0, kRotateNone, &_videoFrame)); + width_, height_, + 0, kRotateNone, &video_frame_)); - for (uint32_t runIdx = 0; runIdx < NumRuns; runIdx++) - { - // initiate test timer + for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { + // Initiate test timer. t0 = TickTime::Now(); // Init the sourceFrame with a timestamp. - _videoFrame.set_render_time_ms(t0.MillisecondTimestamp()); - _videoFrame.set_timestamp(t0.MillisecondTimestamp() * 90); + video_frame_.set_render_time_ms(t0.MillisecondTimestamp()); + video_frame_.set_timestamp(t0.MillisecondTimestamp() * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). - TestSize(_videoFrame, 100, 50, 3, 24.0, _vpm); - TestSize(_videoFrame, 352/4, 288/4, 3, 25.2, _vpm); - TestSize(_videoFrame, 352/2, 288/2, 3, 28.1, _vpm); - TestSize(_videoFrame, 352, 288, 3, -1, _vpm); // no resampling. - TestSize(_videoFrame, 2*352, 2*288, 3, 32.2, _vpm); - TestSize(_videoFrame, 400, 256, 3, 31.3, _vpm); - TestSize(_videoFrame, 480, 640, 3, 32.15, _vpm); - TestSize(_videoFrame, 960, 720, 3, 32.2, _vpm); - TestSize(_videoFrame, 1280, 720, 3, 32.15, _vpm); + TestSize(video_frame_, 100, 50, 3, 24.0, vpm_); + TestSize(video_frame_, 352/4, 288/4, 3, 25.2, vpm_); + TestSize(video_frame_, 352/2, 288/2, 3, 28.1, vpm_); + TestSize(video_frame_, 352, 288, 3, -1, vpm_); // no resampling. + TestSize(video_frame_, 2*352, 2*288, 3, 32.2, vpm_); + TestSize(video_frame_, 400, 256, 3, 31.3, vpm_); + TestSize(video_frame_, 480, 640, 3, 32.15, vpm_); + TestSize(video_frame_, 960, 720, 3, 32.2, vpm_); + TestSize(video_frame_, 1280, 720, 3, 32.15, vpm_); // Upsampling to odd size. - TestSize(_videoFrame, 501, 333, 3, 32.05, _vpm); + TestSize(video_frame_, 501, 333, 3, 32.05, vpm_); // Downsample to odd size. - TestSize(_videoFrame, 281, 175, 3, 29.3, _vpm); + TestSize(video_frame_, 281, 175, 3, 29.3, vpm_); // stop timer t1 = TickTime::Now(); - accTicks += (t1 - t0); + acc_ticks += (t1 - t0); - if (accTicks.Microseconds() < minRuntime || runIdx == 0) { - minRuntime = accTicks.Microseconds(); + if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { + min_runtime = acc_ticks.Microseconds(); } - avgRuntime += accTicks.Microseconds(); + avg_runtime += acc_ticks.Microseconds(); } printf("\nAverage run time = %d us / frame\n", - //static_cast(avgRuntime / frameNum / NumRuns)); - static_cast(avgRuntime)); + //static_cast(avg_runtime / frameNum / NumRuns)); + static_cast(avg_runtime)); printf("Min run time = %d us / frame\n\n", - //static_cast(minRuntime / frameNum)); - static_cast(minRuntime)); + //static_cast(min_runtime / frameNum)); + static_cast(min_runtime)); } -void TestSize(const I420VideoFrame& source_frame, int target_width, - int target_height, int mode, double expected_psnr, +void TestSize(const I420VideoFrame& source_frame, int targetwidth_, + int targetheight_, int mode, double expected_psnr, VideoProcessingModule* vpm) { - int source_width = source_frame.width(); - int source_height = source_frame.height(); + int sourcewidth_ = source_frame.width(); + int sourceheight_ = source_frame.height(); I420VideoFrame* out_frame = NULL; - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetwidth_, targetheight_, 30)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); if (out_frame) { @@ -321,19 +309,19 @@ void TestSize(const I420VideoFrame& source_frame, int target_width, // (2) scale the resampled frame (|out_frame|) back to the original size and // compute PSNR relative to |source_frame| (for automatic verification). // (3) write out the processed frame for viewing. - if (target_width != static_cast(source_width) || - target_height != static_cast(source_height)) { + if (targetwidth_ != static_cast(sourcewidth_) || + targetheight_ != static_cast(sourceheight_)) { // Write the processed frame to file for visual inspection. std::ostringstream filename; filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << source_width << "x" << source_height << "_to_" << - target_width << "x" << target_height << "_30Hz_P420.yuv"; + "from_" << sourcewidth_ << "x" << sourceheight_ << "_to_" << + targetwidth_ << "x" << targetheight_ << "_30Hz_P420.yuv"; std::cout << "Watch " << filename.str() << " and verify that it is okay." << std::endl; FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { fprintf(stderr, "Failed to write frame for scaling to width/height: " - " %d %d \n", target_width, target_height); + " %d %d \n", targetwidth_, targetheight_); return; } fclose(stand_alone_file); @@ -342,8 +330,8 @@ void TestSize(const I420VideoFrame& source_frame, int target_width, resampled_source_frame.CopyFrame(*out_frame); // Scale |resampled_source_frame| back to original/source size. - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(source_width, - source_height, + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(sourcewidth_, + sourceheight_, 30)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, &out_frame)); @@ -351,14 +339,14 @@ void TestSize(const I420VideoFrame& source_frame, int target_width, // Write the processed frame to file for visual inspection. std::ostringstream filename2; filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << target_width << "x" << target_height << "_to_" << - source_width << "x" << source_height << "_30Hz_P420.yuv"; + "from_" << targetwidth_ << "x" << targetheight_ << "_to_" << + sourcewidth_ << "x" << sourceheight_ << "_30Hz_P420.yuv"; std::cout << "Watch " << filename2.str() << " and verify that it is okay." << std::endl; stand_alone_file = fopen(filename2.str().c_str(), "wb"); if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { fprintf(stderr, "Failed to write frame for scaling to width/height " - "%d %d \n", source_width, source_height); + "%d %d \n", sourcewidth_, sourceheight_); return; } fclose(stand_alone_file); @@ -368,7 +356,7 @@ void TestSize(const I420VideoFrame& source_frame, int target_width, EXPECT_GT(psnr, expected_psnr); printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " "source which is scaled down/up to: %d %d, and back to source size \n", - psnr, source_width, source_height, target_width, target_height); + psnr, sourcewidth_, sourceheight_, targetwidth_, targetheight_); } } diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h index db8841b5da..6daf9c2fd9 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h @@ -18,31 +18,28 @@ namespace webrtc { -class VideoProcessingModuleTest : public ::testing::Test -{ -protected: - VideoProcessingModuleTest(); - virtual void SetUp(); - virtual void TearDown(); - static void SetUpTestCase() - { - Trace::CreateTrace(); - std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt"; - ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str())); - } - static void TearDownTestCase() - { - Trace::ReturnTrace(); - } - VideoProcessingModule* _vpm; - FILE* _sourceFile; - I420VideoFrame _videoFrame; - const int _width; - const int _half_width; - const int _height; - const int _size_y; - const int _size_uv; - const unsigned int _frame_length; +class VideoProcessingModuleTest : public ::testing::Test { + protected: + VideoProcessingModuleTest(); + virtual void SetUp(); + virtual void TearDown(); + static void SetUpTestCase() { + Trace::CreateTrace(); + std::string trace_file = webrtc::test::OutputPath() + "VPMTrace.txt"; + ASSERT_EQ(0, Trace::SetTraceFile(trace_file.c_str())); + } + static void TearDownTestCase() { + Trace::ReturnTrace(); + } + VideoProcessingModule* vpm_; + FILE* source_file_; + I420VideoFrame video_frame_; + const int width_; + const int half_width_; + const int height_; + const int size_y_; + const int size_uv_; + const unsigned int frame_length_; }; } // namespace webrtc -- cgit v1.2.3 From b5bc098e204c8ad3122e2de9ac2f89f99f9b1ee0 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Mon, 25 Nov 2013 09:06:33 +0000 Subject: Clear empty video frames in unittest so DrMemory will allow them to be read without an uninitialized read error. BUG=libyuv:263 TESTED=drmemory out\Debug\modules_unittests.exe --gtest_filter=*PreprocessorLogic R=kjellander@webrtc.org, mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/4319004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5168 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/video_processing_unittest.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 89c59ec8b1..6e54923063 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -45,7 +45,10 @@ void VideoProcessingModuleTest::SetUp() { ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, half_width_, half_width_)); - + // Clear video frame so DrMemory/Valgrind will allow reads of the buffer. + memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane)); + memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane)); + memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane)); const std::string video_file = webrtc::test::ResourcePath("foreman_cif", "yuv"); source_file_ = fopen(video_file.c_str(),"rb"); -- cgit v1.2.3 From 8f69330310bf786cff373c225967e7459fb0b560 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Fri, 25 Apr 2014 23:10:28 +0000 Subject: Replace scoped_array with scoped_ptr. scoped_array is deprecated. This was done using a Chromium clang tool: http://src.chromium.org/viewvc/chrome/trunk/src/tools/clang/rewrite_scoped_ar... except for the few not-built-on-Linux files which were updated manually. TESTED=trybots BUG=2515 R=niklas.enbom@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12429004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5985 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/brightness_detection_test.cc | 2 +- .../main/test/unit_test/color_enhancement_test.cc | 6 +++--- .../video_processing/main/test/unit_test/content_metrics_test.cc | 2 +- .../video_processing/main/test/unit_test/deflickering_test.cc | 2 +- .../video_processing/main/test/unit_test/denoising_test.cc | 2 +- .../main/test/unit_test/video_processing_unittest.cc | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index d7ac72908a..c53c1fb838 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -19,7 +19,7 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) uint32_t frameNum = 0; int32_t brightnessWarning = 0; uint32_t warningCount = 0; - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index fc560bef13..c1cd462319 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -39,7 +39,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; uint32_t frameNum = 0; - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { @@ -86,7 +86,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) width_, half_width_, half_width_); // Compare frame-by-frame. - scoped_array ref_buffer(new uint8_t[frame_length_]); + scoped_ptr ref_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, modFile) == frame_length_) { @@ -114,7 +114,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) // Verify that all color pixels are enhanced, and no luminance values are // altered. - scoped_array testFrame(new uint8_t[frame_length_]); + scoped_ptr testFrame(new uint8_t[frame_length_]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 36a1ad7625..c0d1ab4343 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -23,7 +23,7 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) { ca__c.Initialize(width_,height_); ca__sse.Initialize(width_,height_); - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { // Using ConvertToI420 to add stride to the image. diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 0fa3f48b4f..1bf53fc897 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -43,7 +43,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) "Could not open output file: " << output_file << "\n"; printf("\nRun time [us / frame]:\n"); - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { TickTime t0; diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc index 3023a2d7af..c00db6ab57 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -49,7 +49,7 @@ TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) int32_t modifiedPixels = 0; frameNum = 0; - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 6e54923063..9d70e67a12 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -89,7 +89,7 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { TEST_F(VideoProcessingModuleTest, HandleBadStats) { VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -129,7 +129,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { I420VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -172,7 +172,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { TEST_F(VideoProcessingModuleTest, FrameStats) { VideoProcessingModule::FrameStats stats; - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -242,7 +242,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { vpm_->EnableTemporalDecimation(false); // Reading test frame - scoped_array video_buffer(new uint8_t[frame_length_]); + scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); // Using ConvertToI420 to add stride to the image. -- cgit v1.2.3 From 21a5d449b7d8f2ef447daaba20f90a0aa90f6113 Mon Sep 17 00:00:00 2001 From: "wu@webrtc.org" Date: Thu, 29 May 2014 19:43:26 +0000 Subject: Increase VPMVideoDecimator's initial max_frame_rate_ to 60, which allow us potentially do 60fps. BUG= R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/21499006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6274 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_processing/main/test/unit_test/video_processing_unittest.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 9d70e67a12..973552c805 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -118,7 +118,6 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) { EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetMaxFramerate(0)); I420VideoFrame *out_frame = NULL; EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(video_frame_, @@ -200,7 +199,6 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { // Disable temporal sampling (frame dropping). vpm_->EnableTemporalDecimation(false); int resolution = 100; - EXPECT_EQ(VPM_OK, vpm_->SetMaxFramerate(30)); EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 15)); EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); // Disable spatial sampling. -- cgit v1.2.3 From bc7387125138d23fb61ddb9152072aca5055d00a Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 15 Jul 2014 09:50:40 +0000 Subject: Remove the VPM denoiser. The VPM denoiser give bad results, is slow and has not been used in practice. Instead we use the VP8 denoiser. Testing this denoiser takes up a lot of runtime on linux_memcheck (about 4 minutes) which we can do without. BUG= R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/16069004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6688 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/denoising_test.cc | 136 --------------------- .../test/unit_test/video_processing_unittest.cc | 17 --- 2 files changed, 153 deletions(-) delete mode 100644 webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc b/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc deleted file mode 100644 index c00db6ab57..0000000000 --- a/webrtc/modules/video_processing/main/test/unit_test/denoising_test.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include - -#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" -#include "webrtc/system_wrappers/interface/tick_util.h" -#include "webrtc/test/testsupport/fileutils.h" -#include "webrtc/test/testsupport/gtest_disable.h" - -namespace webrtc { - -TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) -{ - enum { NumRuns = 10 }; - uint32_t frameNum = 0; - - int64_t min_runtime = 0; - int64_t avg_runtime = 0; - - const std::string denoise_filename = - webrtc::test::OutputPath() + "denoise_testfile.yuv"; - FILE* denoiseFile = fopen(denoise_filename.c_str(), "wb"); - ASSERT_TRUE(denoiseFile != NULL) << - "Could not open output file: " << denoise_filename << "\n"; - - const std::string noise_filename = - webrtc::test::OutputPath() + "noise_testfile.yuv"; - FILE* noiseFile = fopen(noise_filename.c_str(), "wb"); - ASSERT_TRUE(noiseFile != NULL) << - "Could not open noisy file: " << noise_filename << "\n"; - - printf("\nRun time [us / frame]:\n"); - for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) - { - TickTime t0; - TickTime t1; - TickInterval acc_ticks; - int32_t modifiedPixels = 0; - - frameNum = 0; - scoped_ptr video_buffer(new uint8_t[frame_length_]); - while (fread(video_buffer.get(), 1, frame_length_, source_file_) == - frame_length_) - { - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); - frameNum++; - uint8_t* sourceBuffer = video_frame_.buffer(kYPlane); - - // Add noise to a part in video stream - // Random noise - // TODO: investigate the effectiveness of this test. - - for (int ir = 0; ir < height_; ir++) - { - uint32_t ik = ir * width_; - for (int ic = 0; ic < width_; ic++) - { - uint8_t r = rand() % 16; - r -= 8; - if (ir < height_ / 4) - r = 0; - if (ir >= 3 * height_ / 4) - r = 0; - if (ic < width_ / 4) - r = 0; - if (ic >= 3 * width_ / 4) - r = 0; - - /*uint8_t pixelValue = 0; - if (ir >= height_ / 2) - { // Region 3 or 4 - pixelValue = 170; - } - if (ic >= width_ / 2) - { // Region 2 or 4 - pixelValue += 85; - } - pixelValue += r; - sourceBuffer[ik + ic] = pixelValue; - */ - sourceBuffer[ik + ic] += r; - } - } - - if (run_idx == 0) - { - if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { - return; - } - } - - t0 = TickTime::Now(); - ASSERT_GE(modifiedPixels = vpm_->Denoising(&video_frame_), 0); - t1 = TickTime::Now(); - acc_ticks += (t1 - t0); - - if (run_idx == 0) - { - if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { - return; - } - } - } - ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; - - printf("%u\n", static_cast(acc_ticks.Microseconds() / frameNum)); - if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) - { - min_runtime = acc_ticks.Microseconds(); - } - avg_runtime += acc_ticks.Microseconds(); - - rewind(source_file_); - } - ASSERT_EQ(0, fclose(denoiseFile)); - ASSERT_EQ(0, fclose(noiseFile)); - printf("\nAverage run time = %d us / frame\n", - static_cast(avg_runtime / frameNum / NumRuns)); - printf("Min run time = %d us / frame\n\n", - static_cast(min_runtime / frameNum)); -} - -} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 973552c805..b12450386f 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -82,8 +82,6 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { EXPECT_EQ(-1, vpm_->Deflickering(&videoFrame, &stats)); - EXPECT_EQ(-1, vpm_->Denoising(&videoFrame)); - EXPECT_EQ(-3, vpm_->BrightnessDetection(videoFrame, stats)); } @@ -113,8 +111,6 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) { EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); - EXPECT_EQ(-1, vpm_->Denoising(&video_frame_)); - EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); @@ -143,19 +139,6 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { ASSERT_EQ(0, vpm_->Deflickering(&video_frame2, &stats)); EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); - ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, - source_file_)); - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); - video_frame2.CopyFrame(video_frame_); - EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); - ASSERT_GE(vpm_->Denoising(&video_frame_), 0); - vpm_->Reset(); - ASSERT_GE(vpm_->Denoising(&video_frame2), 0); - EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); - ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, -- cgit v1.2.3 From 809986b95f003bb35289e50f79adbbfe43f05edf Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Tue, 11 Nov 2014 09:51:30 +0000 Subject: webrtc::Scaler: Preserve aspect ratio BUG=3936 R=glaznev@webrtc.org, stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/28969004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7679 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 269 ++++++++++++--------- 1 file changed, 157 insertions(+), 112 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index b12450386f..cbe939bb21 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -18,16 +18,34 @@ namespace webrtc { -// The |sourceFrame| is scaled to |targetwidth_|,|targetheight_|, using the -// filter mode set to |mode|. The |expected_psnr| is used to verify basic -// quality when the resampled frame is scaled back up/down to the -// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than -// actual PSNR verified under the same conditions. -void TestSize(const I420VideoFrame& sourceFrame, int targetwidth_, - int targetheight_, int mode, double expected_psnr, - VideoProcessingModule* vpm); +static void PreprocessFrameAndVerify(const I420VideoFrame& source, + int target_width, + int target_height, + VideoProcessingModule* vpm, + I420VideoFrame** out_frame); +static void CropFrame(const uint8_t* source_data, + int source_width, + int source_height, + int offset_x, + int offset_y, + int cropped_width, + int cropped_height, + I420VideoFrame* cropped_frame); +// The |source_data| is cropped and scaled to |target_width| x |target_height|, +// and then scaled back to the expected cropped size. |expected_psnr| is used to +// verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR +// verified under the same conditions. +static void TestSize(const I420VideoFrame& source_frame, + const I420VideoFrame& cropped_source_frame, + int target_width, + int target_height, + double expected_psnr, + VideoProcessingModule* vpm); bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); + const webrtc::I420VideoFrame& frame2); +static void WriteProcessedFrameForVisualInspection( + const I420VideoFrame& source, + const I420VideoFrame& processed); VideoProcessingModuleTest::VideoProcessingModuleTest() : vpm_(NULL), @@ -190,13 +208,8 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { I420VideoFrame* out_frame = NULL; // Set rescaling => output frame != NULL. vpm_->SetInputFrameResampleMode(kFastRescaling); - EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); - EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); - EXPECT_FALSE(out_frame == NULL); - if (out_frame) { - EXPECT_EQ(resolution, out_frame->width()); - EXPECT_EQ(resolution, out_frame->height()); - } + PreprocessFrameAndVerify(video_frame_, resolution, resolution, vpm_, + &out_frame); // No rescaling=> output frame = NULL. vpm_->SetInputFrameResampleMode(kNoRescaling); EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); @@ -207,11 +220,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { enum { NumRuns = 1 }; int64_t min_runtime = 0; - int64_t avg_runtime = 0; - - TickTime t0; - TickTime t1; - TickInterval acc_ticks; + int64_t total_runtime = 0; rewind(source_file_); ASSERT_TRUE(source_file_ != NULL) << @@ -230,118 +239,138 @@ TEST_F(VideoProcessingModuleTest, Resampler) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 0, kRotateNone, &video_frame_)); + // Cropped source frame that will contain the expected visible region. + I420VideoFrame cropped_source_frame; + cropped_source_frame.CopyFrame(video_frame_); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { // Initiate test timer. - t0 = TickTime::Now(); + const TickTime time_start = TickTime::Now(); // Init the sourceFrame with a timestamp. - video_frame_.set_render_time_ms(t0.MillisecondTimestamp()); - video_frame_.set_timestamp(t0.MillisecondTimestamp() * 90); + video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); + video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. - // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). - TestSize(video_frame_, 100, 50, 3, 24.0, vpm_); - TestSize(video_frame_, 352/4, 288/4, 3, 25.2, vpm_); - TestSize(video_frame_, 352/2, 288/2, 3, 28.1, vpm_); - TestSize(video_frame_, 352, 288, 3, -1, vpm_); // no resampling. - TestSize(video_frame_, 2*352, 2*288, 3, 32.2, vpm_); - TestSize(video_frame_, 400, 256, 3, 31.3, vpm_); - TestSize(video_frame_, 480, 640, 3, 32.15, vpm_); - TestSize(video_frame_, 960, 720, 3, 32.2, vpm_); - TestSize(video_frame_, 1280, 720, 3, 32.15, vpm_); + // Pure scaling: + TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vpm_); + TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vpm_); + // No resampling: + TestSize(video_frame_, video_frame_, width_, height_, -1, vpm_); + TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vpm_); + + // Scaling and cropping. The cropped source frame is the largest center + // aligned region that can be used from the source while preserving aspect + // ratio. + CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vpm_); + // Upsampling to odd size. - TestSize(video_frame_, 501, 333, 3, 32.05, vpm_); + CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vpm_); // Downsample to odd size. - TestSize(video_frame_, 281, 175, 3, 29.3, vpm_); - - // stop timer - t1 = TickTime::Now(); - acc_ticks += (t1 - t0); - - if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { - min_runtime = acc_ticks.Microseconds(); + CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vpm_); + + // Stop timer. + const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); + if (runtime < min_runtime || run_idx == 0) { + min_runtime = runtime; } - avg_runtime += acc_ticks.Microseconds(); + total_runtime += runtime; } printf("\nAverage run time = %d us / frame\n", - //static_cast(avg_runtime / frameNum / NumRuns)); - static_cast(avg_runtime)); + static_cast(total_runtime)); printf("Min run time = %d us / frame\n\n", - //static_cast(min_runtime / frameNum)); static_cast(min_runtime)); } -void TestSize(const I420VideoFrame& source_frame, int targetwidth_, - int targetheight_, int mode, double expected_psnr, - VideoProcessingModule* vpm) { - int sourcewidth_ = source_frame.width(); - int sourceheight_ = source_frame.height(); - I420VideoFrame* out_frame = NULL; - - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetwidth_, targetheight_, 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); - - if (out_frame) { - EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); - EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); +void PreprocessFrameAndVerify(const I420VideoFrame& source, + int target_width, + int target_height, + VideoProcessingModule* vpm, + I420VideoFrame** out_frame) { + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source, out_frame)); + + // If no resizing is needed, expect NULL. + if (target_width == source.width() && target_height == source.height()) { + EXPECT_EQ(NULL, *out_frame); + return; } - // If the frame was resampled (scale changed) then: - // (1) verify the new size and write out processed frame for viewing. - // (2) scale the resampled frame (|out_frame|) back to the original size and - // compute PSNR relative to |source_frame| (for automatic verification). - // (3) write out the processed frame for viewing. - if (targetwidth_ != static_cast(sourcewidth_) || - targetheight_ != static_cast(sourceheight_)) { - // Write the processed frame to file for visual inspection. - std::ostringstream filename; - filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << sourcewidth_ << "x" << sourceheight_ << "_to_" << - targetwidth_ << "x" << targetheight_ << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename.str() << " and verify that it is okay." - << std::endl; - FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height: " - " %d %d \n", targetwidth_, targetheight_); - return; - } - fclose(stand_alone_file); + // Verify the resampled frame. + EXPECT_TRUE(*out_frame != NULL); + EXPECT_EQ(source.render_time_ms(), (*out_frame)->render_time_ms()); + EXPECT_EQ(source.timestamp(), (*out_frame)->timestamp()); + EXPECT_EQ(target_width, (*out_frame)->width()); + EXPECT_EQ(target_height, (*out_frame)->height()); +} - I420VideoFrame resampled_source_frame; - resampled_source_frame.CopyFrame(*out_frame); - - // Scale |resampled_source_frame| back to original/source size. - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(sourcewidth_, - sourceheight_, - 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, - &out_frame)); - - // Write the processed frame to file for visual inspection. - std::ostringstream filename2; - filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << targetwidth_ << "x" << targetheight_ << "_to_" << - sourcewidth_ << "x" << sourceheight_ << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename2.str() << " and verify that it is okay." - << std::endl; - stand_alone_file = fopen(filename2.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height " - "%d %d \n", sourcewidth_, sourceheight_); - return; - } - fclose(stand_alone_file); +void CropFrame(const uint8_t* source_data, + int source_width, + int source_height, + int offset_x, + int offset_y, + int cropped_width, + int cropped_height, + I420VideoFrame* cropped_frame) { + cropped_frame->set_width(cropped_width); + cropped_frame->set_height(cropped_height); + EXPECT_EQ(0, + ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, + source_height, 0, kRotateNone, cropped_frame)); +} - // Compute the PSNR and check expectation. - double psnr = I420PSNR(&source_frame, out_frame); - EXPECT_GT(psnr, expected_psnr); - printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " - "source which is scaled down/up to: %d %d, and back to source size \n", - psnr, sourcewidth_, sourceheight_, targetwidth_, targetheight_); - } +void TestSize(const I420VideoFrame& source_frame, + const I420VideoFrame& cropped_source_frame, + int target_width, + int target_height, + double expected_psnr, + VideoProcessingModule* vpm) { + // Resample source_frame to out_frame. + I420VideoFrame* out_frame = NULL; + vpm->SetInputFrameResampleMode(kBox); + PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, + &out_frame); + if (out_frame == NULL) + return; + WriteProcessedFrameForVisualInspection(source_frame, *out_frame); + + // Scale |resampled_source_frame| back to the source scale. + I420VideoFrame resampled_source_frame; + resampled_source_frame.CopyFrame(*out_frame); + PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), + cropped_source_frame.height(), vpm, &out_frame); + WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); + + // Compute PSNR against the cropped source frame and check expectation. + double psnr = I420PSNR(&cropped_source_frame, out_frame); + EXPECT_GT(psnr, expected_psnr); + printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " + "source which is scaled down/up to: %d %d, and back to source size \n", + psnr, source_frame.width(), source_frame.height(), + target_width, target_height); } bool CompareFrames(const webrtc::I420VideoFrame& frame1, @@ -360,4 +389,20 @@ bool CompareFrames(const webrtc::I420VideoFrame& frame1, return true; } +void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, + const I420VideoFrame& processed) { + // Write the processed frame to file for visual inspection. + std::ostringstream filename; + filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() + << "x" << source.height() << "_to_" << processed.width() << "x" + << processed.height() << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename.str() << " and verify that it is okay." + << std::endl; + FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); + if (PrintI420VideoFrame(processed, stand_alone_file) < 0) + std::cerr << "Failed to write: " << filename.str() << std::endl; + if (stand_alone_file) + fclose(stand_alone_file); +} + } // namespace webrtc -- cgit v1.2.3 From f7c5d4fac7ced81f6a9d07512959c61b8a01c2e4 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Tue, 11 Nov 2014 13:12:09 +0000 Subject: Revert 7679 "webrtc::Scaler: Preserve aspect ratio" > webrtc::Scaler: Preserve aspect ratio > > BUG=3936 > R=glaznev@webrtc.org, stefan@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/28969004 TBR=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/30989004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7682 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 269 +++++++++------------ 1 file changed, 112 insertions(+), 157 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index cbe939bb21..b12450386f 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -18,34 +18,16 @@ namespace webrtc { -static void PreprocessFrameAndVerify(const I420VideoFrame& source, - int target_width, - int target_height, - VideoProcessingModule* vpm, - I420VideoFrame** out_frame); -static void CropFrame(const uint8_t* source_data, - int source_width, - int source_height, - int offset_x, - int offset_y, - int cropped_width, - int cropped_height, - I420VideoFrame* cropped_frame); -// The |source_data| is cropped and scaled to |target_width| x |target_height|, -// and then scaled back to the expected cropped size. |expected_psnr| is used to -// verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR -// verified under the same conditions. -static void TestSize(const I420VideoFrame& source_frame, - const I420VideoFrame& cropped_source_frame, - int target_width, - int target_height, - double expected_psnr, - VideoProcessingModule* vpm); +// The |sourceFrame| is scaled to |targetwidth_|,|targetheight_|, using the +// filter mode set to |mode|. The |expected_psnr| is used to verify basic +// quality when the resampled frame is scaled back up/down to the +// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than +// actual PSNR verified under the same conditions. +void TestSize(const I420VideoFrame& sourceFrame, int targetwidth_, + int targetheight_, int mode, double expected_psnr, + VideoProcessingModule* vpm); bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); -static void WriteProcessedFrameForVisualInspection( - const I420VideoFrame& source, - const I420VideoFrame& processed); + const webrtc::I420VideoFrame& frame2); VideoProcessingModuleTest::VideoProcessingModuleTest() : vpm_(NULL), @@ -208,8 +190,13 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { I420VideoFrame* out_frame = NULL; // Set rescaling => output frame != NULL. vpm_->SetInputFrameResampleMode(kFastRescaling); - PreprocessFrameAndVerify(video_frame_, resolution, resolution, vpm_, - &out_frame); + EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); + EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); + EXPECT_FALSE(out_frame == NULL); + if (out_frame) { + EXPECT_EQ(resolution, out_frame->width()); + EXPECT_EQ(resolution, out_frame->height()); + } // No rescaling=> output frame = NULL. vpm_->SetInputFrameResampleMode(kNoRescaling); EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); @@ -220,7 +207,11 @@ TEST_F(VideoProcessingModuleTest, Resampler) { enum { NumRuns = 1 }; int64_t min_runtime = 0; - int64_t total_runtime = 0; + int64_t avg_runtime = 0; + + TickTime t0; + TickTime t1; + TickInterval acc_ticks; rewind(source_file_); ASSERT_TRUE(source_file_ != NULL) << @@ -239,138 +230,118 @@ TEST_F(VideoProcessingModuleTest, Resampler) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 0, kRotateNone, &video_frame_)); - // Cropped source frame that will contain the expected visible region. - I420VideoFrame cropped_source_frame; - cropped_source_frame.CopyFrame(video_frame_); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { // Initiate test timer. - const TickTime time_start = TickTime::Now(); + t0 = TickTime::Now(); // Init the sourceFrame with a timestamp. - video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); - video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); + video_frame_.set_render_time_ms(t0.MillisecondTimestamp()); + video_frame_.set_timestamp(t0.MillisecondTimestamp() * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. - // Pure scaling: - TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vpm_); - TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vpm_); - // No resampling: - TestSize(video_frame_, video_frame_, width_, height_, -1, vpm_); - TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vpm_); - - // Scaling and cropping. The cropped source frame is the largest center - // aligned region that can be used from the source while preserving aspect - // ratio. - CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vpm_); - - CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vpm_); - - CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vpm_); - - CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vpm_); - - CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vpm_); - + // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). + TestSize(video_frame_, 100, 50, 3, 24.0, vpm_); + TestSize(video_frame_, 352/4, 288/4, 3, 25.2, vpm_); + TestSize(video_frame_, 352/2, 288/2, 3, 28.1, vpm_); + TestSize(video_frame_, 352, 288, 3, -1, vpm_); // no resampling. + TestSize(video_frame_, 2*352, 2*288, 3, 32.2, vpm_); + TestSize(video_frame_, 400, 256, 3, 31.3, vpm_); + TestSize(video_frame_, 480, 640, 3, 32.15, vpm_); + TestSize(video_frame_, 960, 720, 3, 32.2, vpm_); + TestSize(video_frame_, 1280, 720, 3, 32.15, vpm_); // Upsampling to odd size. - CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vpm_); + TestSize(video_frame_, 501, 333, 3, 32.05, vpm_); // Downsample to odd size. - CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, - &cropped_source_frame); - TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vpm_); - - // Stop timer. - const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); - if (runtime < min_runtime || run_idx == 0) { - min_runtime = runtime; + TestSize(video_frame_, 281, 175, 3, 29.3, vpm_); + + // stop timer + t1 = TickTime::Now(); + acc_ticks += (t1 - t0); + + if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { + min_runtime = acc_ticks.Microseconds(); } - total_runtime += runtime; + avg_runtime += acc_ticks.Microseconds(); } printf("\nAverage run time = %d us / frame\n", - static_cast(total_runtime)); + //static_cast(avg_runtime / frameNum / NumRuns)); + static_cast(avg_runtime)); printf("Min run time = %d us / frame\n\n", + //static_cast(min_runtime / frameNum)); static_cast(min_runtime)); } -void PreprocessFrameAndVerify(const I420VideoFrame& source, - int target_width, - int target_height, - VideoProcessingModule* vpm, - I420VideoFrame** out_frame) { - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source, out_frame)); - - // If no resizing is needed, expect NULL. - if (target_width == source.width() && target_height == source.height()) { - EXPECT_EQ(NULL, *out_frame); - return; +void TestSize(const I420VideoFrame& source_frame, int targetwidth_, + int targetheight_, int mode, double expected_psnr, + VideoProcessingModule* vpm) { + int sourcewidth_ = source_frame.width(); + int sourceheight_ = source_frame.height(); + I420VideoFrame* out_frame = NULL; + + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetwidth_, targetheight_, 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); + + if (out_frame) { + EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); + EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); } - // Verify the resampled frame. - EXPECT_TRUE(*out_frame != NULL); - EXPECT_EQ(source.render_time_ms(), (*out_frame)->render_time_ms()); - EXPECT_EQ(source.timestamp(), (*out_frame)->timestamp()); - EXPECT_EQ(target_width, (*out_frame)->width()); - EXPECT_EQ(target_height, (*out_frame)->height()); -} + // If the frame was resampled (scale changed) then: + // (1) verify the new size and write out processed frame for viewing. + // (2) scale the resampled frame (|out_frame|) back to the original size and + // compute PSNR relative to |source_frame| (for automatic verification). + // (3) write out the processed frame for viewing. + if (targetwidth_ != static_cast(sourcewidth_) || + targetheight_ != static_cast(sourceheight_)) { + // Write the processed frame to file for visual inspection. + std::ostringstream filename; + filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << sourcewidth_ << "x" << sourceheight_ << "_to_" << + targetwidth_ << "x" << targetheight_ << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename.str() << " and verify that it is okay." + << std::endl; + FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { + fprintf(stderr, "Failed to write frame for scaling to width/height: " + " %d %d \n", targetwidth_, targetheight_); + return; + } + fclose(stand_alone_file); -void CropFrame(const uint8_t* source_data, - int source_width, - int source_height, - int offset_x, - int offset_y, - int cropped_width, - int cropped_height, - I420VideoFrame* cropped_frame) { - cropped_frame->set_width(cropped_width); - cropped_frame->set_height(cropped_height); - EXPECT_EQ(0, - ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, - source_height, 0, kRotateNone, cropped_frame)); -} + I420VideoFrame resampled_source_frame; + resampled_source_frame.CopyFrame(*out_frame); + + // Scale |resampled_source_frame| back to original/source size. + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(sourcewidth_, + sourceheight_, + 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, + &out_frame)); + + // Write the processed frame to file for visual inspection. + std::ostringstream filename2; + filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << + "from_" << targetwidth_ << "x" << targetheight_ << "_to_" << + sourcewidth_ << "x" << sourceheight_ << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename2.str() << " and verify that it is okay." + << std::endl; + stand_alone_file = fopen(filename2.str().c_str(), "wb"); + if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { + fprintf(stderr, "Failed to write frame for scaling to width/height " + "%d %d \n", sourcewidth_, sourceheight_); + return; + } + fclose(stand_alone_file); -void TestSize(const I420VideoFrame& source_frame, - const I420VideoFrame& cropped_source_frame, - int target_width, - int target_height, - double expected_psnr, - VideoProcessingModule* vpm) { - // Resample source_frame to out_frame. - I420VideoFrame* out_frame = NULL; - vpm->SetInputFrameResampleMode(kBox); - PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, - &out_frame); - if (out_frame == NULL) - return; - WriteProcessedFrameForVisualInspection(source_frame, *out_frame); - - // Scale |resampled_source_frame| back to the source scale. - I420VideoFrame resampled_source_frame; - resampled_source_frame.CopyFrame(*out_frame); - PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), - cropped_source_frame.height(), vpm, &out_frame); - WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); - - // Compute PSNR against the cropped source frame and check expectation. - double psnr = I420PSNR(&cropped_source_frame, out_frame); - EXPECT_GT(psnr, expected_psnr); - printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " - "source which is scaled down/up to: %d %d, and back to source size \n", - psnr, source_frame.width(), source_frame.height(), - target_width, target_height); + // Compute the PSNR and check expectation. + double psnr = I420PSNR(&source_frame, out_frame); + EXPECT_GT(psnr, expected_psnr); + printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " + "source which is scaled down/up to: %d %d, and back to source size \n", + psnr, sourcewidth_, sourceheight_, targetwidth_, targetheight_); + } } bool CompareFrames(const webrtc::I420VideoFrame& frame1, @@ -389,20 +360,4 @@ bool CompareFrames(const webrtc::I420VideoFrame& frame1, return true; } -void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, - const I420VideoFrame& processed) { - // Write the processed frame to file for visual inspection. - std::ostringstream filename; - filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() - << "x" << source.height() << "_to_" << processed.width() << "x" - << processed.height() << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename.str() << " and verify that it is okay." - << std::endl; - FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (PrintI420VideoFrame(processed, stand_alone_file) < 0) - std::cerr << "Failed to write: " << filename.str() << std::endl; - if (stand_alone_file) - fclose(stand_alone_file); -} - } // namespace webrtc -- cgit v1.2.3 From ea73ff726705c9af1dd3142dadc3c154a8627b55 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Wed, 12 Nov 2014 09:52:03 +0000 Subject: webrtc::Scaler: Preserve aspect ratio BUG=3936 R=glaznev@webrtc.org, stefan@webrtc.org Committed: https://code.google.com/p/webrtc/source/detail?r=7679 Review URL: https://webrtc-codereview.appspot.com/28969004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7689 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 269 ++++++++++++--------- 1 file changed, 157 insertions(+), 112 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index b12450386f..cbe939bb21 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -18,16 +18,34 @@ namespace webrtc { -// The |sourceFrame| is scaled to |targetwidth_|,|targetheight_|, using the -// filter mode set to |mode|. The |expected_psnr| is used to verify basic -// quality when the resampled frame is scaled back up/down to the -// original/source size. |expected_psnr| is set to be ~0.1/0.05dB lower than -// actual PSNR verified under the same conditions. -void TestSize(const I420VideoFrame& sourceFrame, int targetwidth_, - int targetheight_, int mode, double expected_psnr, - VideoProcessingModule* vpm); +static void PreprocessFrameAndVerify(const I420VideoFrame& source, + int target_width, + int target_height, + VideoProcessingModule* vpm, + I420VideoFrame** out_frame); +static void CropFrame(const uint8_t* source_data, + int source_width, + int source_height, + int offset_x, + int offset_y, + int cropped_width, + int cropped_height, + I420VideoFrame* cropped_frame); +// The |source_data| is cropped and scaled to |target_width| x |target_height|, +// and then scaled back to the expected cropped size. |expected_psnr| is used to +// verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR +// verified under the same conditions. +static void TestSize(const I420VideoFrame& source_frame, + const I420VideoFrame& cropped_source_frame, + int target_width, + int target_height, + double expected_psnr, + VideoProcessingModule* vpm); bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); + const webrtc::I420VideoFrame& frame2); +static void WriteProcessedFrameForVisualInspection( + const I420VideoFrame& source, + const I420VideoFrame& processed); VideoProcessingModuleTest::VideoProcessingModuleTest() : vpm_(NULL), @@ -190,13 +208,8 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { I420VideoFrame* out_frame = NULL; // Set rescaling => output frame != NULL. vpm_->SetInputFrameResampleMode(kFastRescaling); - EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); - EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); - EXPECT_FALSE(out_frame == NULL); - if (out_frame) { - EXPECT_EQ(resolution, out_frame->width()); - EXPECT_EQ(resolution, out_frame->height()); - } + PreprocessFrameAndVerify(video_frame_, resolution, resolution, vpm_, + &out_frame); // No rescaling=> output frame = NULL. vpm_->SetInputFrameResampleMode(kNoRescaling); EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); @@ -207,11 +220,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { enum { NumRuns = 1 }; int64_t min_runtime = 0; - int64_t avg_runtime = 0; - - TickTime t0; - TickTime t1; - TickInterval acc_ticks; + int64_t total_runtime = 0; rewind(source_file_); ASSERT_TRUE(source_file_ != NULL) << @@ -230,118 +239,138 @@ TEST_F(VideoProcessingModuleTest, Resampler) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 0, kRotateNone, &video_frame_)); + // Cropped source frame that will contain the expected visible region. + I420VideoFrame cropped_source_frame; + cropped_source_frame.CopyFrame(video_frame_); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { // Initiate test timer. - t0 = TickTime::Now(); + const TickTime time_start = TickTime::Now(); // Init the sourceFrame with a timestamp. - video_frame_.set_render_time_ms(t0.MillisecondTimestamp()); - video_frame_.set_timestamp(t0.MillisecondTimestamp() * 90); + video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); + video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); // Test scaling to different sizes: source is of |width|/|height| = 352/288. - // Scaling mode in VPM is currently fixed to kScaleBox (mode = 3). - TestSize(video_frame_, 100, 50, 3, 24.0, vpm_); - TestSize(video_frame_, 352/4, 288/4, 3, 25.2, vpm_); - TestSize(video_frame_, 352/2, 288/2, 3, 28.1, vpm_); - TestSize(video_frame_, 352, 288, 3, -1, vpm_); // no resampling. - TestSize(video_frame_, 2*352, 2*288, 3, 32.2, vpm_); - TestSize(video_frame_, 400, 256, 3, 31.3, vpm_); - TestSize(video_frame_, 480, 640, 3, 32.15, vpm_); - TestSize(video_frame_, 960, 720, 3, 32.2, vpm_); - TestSize(video_frame_, 1280, 720, 3, 32.15, vpm_); + // Pure scaling: + TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vpm_); + TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vpm_); + // No resampling: + TestSize(video_frame_, video_frame_, width_, height_, -1, vpm_); + TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vpm_); + + // Scaling and cropping. The cropped source frame is the largest center + // aligned region that can be used from the source while preserving aspect + // ratio. + CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vpm_); + + CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vpm_); + // Upsampling to odd size. - TestSize(video_frame_, 501, 333, 3, 32.05, vpm_); + CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vpm_); // Downsample to odd size. - TestSize(video_frame_, 281, 175, 3, 29.3, vpm_); - - // stop timer - t1 = TickTime::Now(); - acc_ticks += (t1 - t0); - - if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { - min_runtime = acc_ticks.Microseconds(); + CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, + &cropped_source_frame); + TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vpm_); + + // Stop timer. + const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); + if (runtime < min_runtime || run_idx == 0) { + min_runtime = runtime; } - avg_runtime += acc_ticks.Microseconds(); + total_runtime += runtime; } printf("\nAverage run time = %d us / frame\n", - //static_cast(avg_runtime / frameNum / NumRuns)); - static_cast(avg_runtime)); + static_cast(total_runtime)); printf("Min run time = %d us / frame\n\n", - //static_cast(min_runtime / frameNum)); static_cast(min_runtime)); } -void TestSize(const I420VideoFrame& source_frame, int targetwidth_, - int targetheight_, int mode, double expected_psnr, - VideoProcessingModule* vpm) { - int sourcewidth_ = source_frame.width(); - int sourceheight_ = source_frame.height(); - I420VideoFrame* out_frame = NULL; - - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(targetwidth_, targetheight_, 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source_frame, &out_frame)); - - if (out_frame) { - EXPECT_EQ(source_frame.render_time_ms(), out_frame->render_time_ms()); - EXPECT_EQ(source_frame.timestamp(), out_frame->timestamp()); +void PreprocessFrameAndVerify(const I420VideoFrame& source, + int target_width, + int target_height, + VideoProcessingModule* vpm, + I420VideoFrame** out_frame) { + ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); + ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source, out_frame)); + + // If no resizing is needed, expect NULL. + if (target_width == source.width() && target_height == source.height()) { + EXPECT_EQ(NULL, *out_frame); + return; } - // If the frame was resampled (scale changed) then: - // (1) verify the new size and write out processed frame for viewing. - // (2) scale the resampled frame (|out_frame|) back to the original size and - // compute PSNR relative to |source_frame| (for automatic verification). - // (3) write out the processed frame for viewing. - if (targetwidth_ != static_cast(sourcewidth_) || - targetheight_ != static_cast(sourceheight_)) { - // Write the processed frame to file for visual inspection. - std::ostringstream filename; - filename << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << sourcewidth_ << "x" << sourceheight_ << "_to_" << - targetwidth_ << "x" << targetheight_ << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename.str() << " and verify that it is okay." - << std::endl; - FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height: " - " %d %d \n", targetwidth_, targetheight_); - return; - } - fclose(stand_alone_file); + // Verify the resampled frame. + EXPECT_TRUE(*out_frame != NULL); + EXPECT_EQ(source.render_time_ms(), (*out_frame)->render_time_ms()); + EXPECT_EQ(source.timestamp(), (*out_frame)->timestamp()); + EXPECT_EQ(target_width, (*out_frame)->width()); + EXPECT_EQ(target_height, (*out_frame)->height()); +} - I420VideoFrame resampled_source_frame; - resampled_source_frame.CopyFrame(*out_frame); - - // Scale |resampled_source_frame| back to original/source size. - ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(sourcewidth_, - sourceheight_, - 30)); - ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(resampled_source_frame, - &out_frame)); - - // Write the processed frame to file for visual inspection. - std::ostringstream filename2; - filename2 << webrtc::test::OutputPath() << "Resampler_"<< mode << "_" << - "from_" << targetwidth_ << "x" << targetheight_ << "_to_" << - sourcewidth_ << "x" << sourceheight_ << "_30Hz_P420.yuv"; - std::cout << "Watch " << filename2.str() << " and verify that it is okay." - << std::endl; - stand_alone_file = fopen(filename2.str().c_str(), "wb"); - if (PrintI420VideoFrame(*out_frame, stand_alone_file) < 0) { - fprintf(stderr, "Failed to write frame for scaling to width/height " - "%d %d \n", sourcewidth_, sourceheight_); - return; - } - fclose(stand_alone_file); +void CropFrame(const uint8_t* source_data, + int source_width, + int source_height, + int offset_x, + int offset_y, + int cropped_width, + int cropped_height, + I420VideoFrame* cropped_frame) { + cropped_frame->set_width(cropped_width); + cropped_frame->set_height(cropped_height); + EXPECT_EQ(0, + ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, + source_height, 0, kRotateNone, cropped_frame)); +} - // Compute the PSNR and check expectation. - double psnr = I420PSNR(&source_frame, out_frame); - EXPECT_GT(psnr, expected_psnr); - printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " - "source which is scaled down/up to: %d %d, and back to source size \n", - psnr, sourcewidth_, sourceheight_, targetwidth_, targetheight_); - } +void TestSize(const I420VideoFrame& source_frame, + const I420VideoFrame& cropped_source_frame, + int target_width, + int target_height, + double expected_psnr, + VideoProcessingModule* vpm) { + // Resample source_frame to out_frame. + I420VideoFrame* out_frame = NULL; + vpm->SetInputFrameResampleMode(kBox); + PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, + &out_frame); + if (out_frame == NULL) + return; + WriteProcessedFrameForVisualInspection(source_frame, *out_frame); + + // Scale |resampled_source_frame| back to the source scale. + I420VideoFrame resampled_source_frame; + resampled_source_frame.CopyFrame(*out_frame); + PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), + cropped_source_frame.height(), vpm, &out_frame); + WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); + + // Compute PSNR against the cropped source frame and check expectation. + double psnr = I420PSNR(&cropped_source_frame, out_frame); + EXPECT_GT(psnr, expected_psnr); + printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " + "source which is scaled down/up to: %d %d, and back to source size \n", + psnr, source_frame.width(), source_frame.height(), + target_width, target_height); } bool CompareFrames(const webrtc::I420VideoFrame& frame1, @@ -360,4 +389,20 @@ bool CompareFrames(const webrtc::I420VideoFrame& frame1, return true; } +void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, + const I420VideoFrame& processed) { + // Write the processed frame to file for visual inspection. + std::ostringstream filename; + filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() + << "x" << source.height() << "_to_" << processed.width() << "x" + << processed.height() << "_30Hz_P420.yuv"; + std::cout << "Watch " << filename.str() << " and verify that it is okay." + << std::endl; + FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); + if (PrintI420VideoFrame(processed, stand_alone_file) < 0) + std::cerr << "Failed to write: " << filename.str() << std::endl; + if (stand_alone_file) + fclose(stand_alone_file); +} + } // namespace webrtc -- cgit v1.2.3 From 4591fbd09f9cb6e83433c49a12dd8524c2806502 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Thu, 20 Nov 2014 22:28:14 +0000 Subject: Use size_t more consistently for packet/payload lengths. See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information. This CL was reviewed and approved in pieces in the following CLs: https://webrtc-codereview.appspot.com/24209004/ https://webrtc-codereview.appspot.com/24229004/ https://webrtc-codereview.appspot.com/24259004/ https://webrtc-codereview.appspot.com/25109004/ https://webrtc-codereview.appspot.com/26099004/ https://webrtc-codereview.appspot.com/27069004/ https://webrtc-codereview.appspot.com/27969004/ https://webrtc-codereview.appspot.com/27989004/ https://webrtc-codereview.appspot.com/29009004/ https://webrtc-codereview.appspot.com/30929004/ https://webrtc-codereview.appspot.com/30939004/ https://webrtc-codereview.appspot.com/31999004/ Committing as TBR to the original reviewers. BUG=chromium:81439 TEST=none TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom Review URL: https://webrtc-codereview.appspot.com/23129004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_processing/main/test/unit_test/video_processing_unittest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h index 6daf9c2fd9..37e2c02b94 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h @@ -39,7 +39,7 @@ class VideoProcessingModuleTest : public ::testing::Test { const int height_; const int size_y_; const int size_uv_; - const unsigned int frame_length_; + const size_t frame_length_; }; } // namespace webrtc -- cgit v1.2.3 From be29b3b4c6f711f6aa2902863c69a1978b6613a5 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Thu, 19 Feb 2015 15:34:55 +0000 Subject: I420VideoFrame: Remove functions set_width, set_height, and ResetSize The functions set_width, set_height, and ResetSize in I420VideoFrame are not needed and just add complexity. R=perkj@webrtc.org, stefan@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39939004 Cr-Commit-Position: refs/heads/master@{#8434} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8434 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index cbe939bb21..dcf1842a47 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -91,8 +91,6 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. I420VideoFrame videoFrame; - videoFrame.set_width(width_); - videoFrame.set_height(height_); EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); @@ -120,21 +118,21 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { TEST_F(VideoProcessingModuleTest, HandleBadSize) { VideoProcessingModule::FrameStats stats; - video_frame_.ResetSize(); - video_frame_.set_width(width_); - video_frame_.set_height(0); - EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, video_frame_)); + I420VideoFrame bad_frame; + bad_frame.CreateEmptyFrame(width_, 0, width_, (width_ + 1) / 2, + (width_ + 1) / 2); + EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, bad_frame)); - EXPECT_EQ(-1, vpm_->ColorEnhancement(&video_frame_)); + EXPECT_EQ(-1, vpm_->ColorEnhancement(&bad_frame)); - EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&bad_frame, &stats)); - EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(bad_frame, stats)); EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); I420VideoFrame *out_frame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(video_frame_, + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, &out_frame)); } @@ -335,8 +333,10 @@ void CropFrame(const uint8_t* source_data, int cropped_width, int cropped_height, I420VideoFrame* cropped_frame) { - cropped_frame->set_width(cropped_width); - cropped_frame->set_height(cropped_height); + cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, + cropped_width, + (cropped_width + 1) / 2, + (cropped_width + 1) / 2); EXPECT_EQ(0, ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, source_height, 0, kRotateNone, cropped_frame)); -- cgit v1.2.3 From 00b8f6b3643332cce1ee711715f7fbb824d793ca Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Thu, 26 Feb 2015 14:34:55 +0000 Subject: Use base/scoped_ptr.h; system_wrappers/interface/scoped_ptr.h is going away BUG= R=andrew@webrtc.org Review URL: https://webrtc-codereview.appspot.com/36229004 Cr-Commit-Position: refs/heads/master@{#8517} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8517 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/brightness_detection_test.cc | 2 +- .../main/test/unit_test/color_enhancement_test.cc | 6 +++--- .../video_processing/main/test/unit_test/content_metrics_test.cc | 2 +- .../video_processing/main/test/unit_test/deflickering_test.cc | 2 +- .../main/test/unit_test/video_processing_unittest.cc | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index c53c1fb838..69f7fd86d3 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -19,7 +19,7 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) uint32_t frameNum = 0; int32_t brightnessWarning = 0; uint32_t warningCount = 0; - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index c1cd462319..80f230d9fa 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -39,7 +39,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; uint32_t frameNum = 0; - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { @@ -86,7 +86,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) width_, half_width_, half_width_); // Compare frame-by-frame. - scoped_ptr ref_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr ref_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, modFile) == frame_length_) { @@ -114,7 +114,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) // Verify that all color pixels are enhanced, and no luminance values are // altered. - scoped_ptr testFrame(new uint8_t[frame_length_]); + rtc::scoped_ptr testFrame(new uint8_t[frame_length_]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index c0d1ab4343..ca71d551bf 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -23,7 +23,7 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) { ca__c.Initialize(width_,height_); ca__sse.Initialize(width_,height_); - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { // Using ConvertToI420 to add stride to the image. diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 1bf53fc897..01e98d13d0 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -43,7 +43,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) "Could not open output file: " << output_file << "\n"; printf("\nRun time [us / frame]:\n"); - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { TickTime t0; diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index dcf1842a47..6c77911018 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -103,7 +103,7 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { TEST_F(VideoProcessingModuleTest, HandleBadStats) { VideoProcessingModule::FrameStats stats; - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -140,7 +140,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { I420VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -170,7 +170,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { TEST_F(VideoProcessingModuleTest, FrameStats) { VideoProcessingModule::FrameStats stats; - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -230,7 +230,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { vpm_->EnableTemporalDecimation(false); // Reading test frame - scoped_ptr video_buffer(new uint8_t[frame_length_]); + rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); // Using ConvertToI420 to add stride to the image. -- cgit v1.2.3 From 7400e0b87609af0295ca123ad38d01fb7b430329 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Fri, 27 Feb 2015 15:18:26 +0000 Subject: Revert "I420VideoFrame: Remove functions set_width, set_height, and ResetSize" This reverts commit r8434. Reason for revert: Introduced a race condition. If ViECaptureProcess() -> SwapCapturedAndDeliverFrameIfAvailable() is called twice without a call to OnIncomingCapturedFrame() in between (with both captured_frame_ and deliver_frame_ populated), an old frame will be delivered again, since captured_frame_->IsZeroSize() will never be true. BUG=4352 TBR=perkj@webrtc.org, stefan@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/40129004 Cr-Commit-Position: refs/heads/master@{#8530} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8530 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 6c77911018..70e19cc26f 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -91,6 +91,8 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. I420VideoFrame videoFrame; + videoFrame.set_width(width_); + videoFrame.set_height(height_); EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); @@ -118,21 +120,21 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { TEST_F(VideoProcessingModuleTest, HandleBadSize) { VideoProcessingModule::FrameStats stats; - I420VideoFrame bad_frame; - bad_frame.CreateEmptyFrame(width_, 0, width_, (width_ + 1) / 2, - (width_ + 1) / 2); - EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, bad_frame)); + video_frame_.ResetSize(); + video_frame_.set_width(width_); + video_frame_.set_height(0); + EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, video_frame_)); - EXPECT_EQ(-1, vpm_->ColorEnhancement(&bad_frame)); + EXPECT_EQ(-1, vpm_->ColorEnhancement(&video_frame_)); - EXPECT_EQ(-1, vpm_->Deflickering(&bad_frame, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); - EXPECT_EQ(-3, vpm_->BrightnessDetection(bad_frame, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); I420VideoFrame *out_frame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(video_frame_, &out_frame)); } @@ -333,10 +335,8 @@ void CropFrame(const uint8_t* source_data, int cropped_width, int cropped_height, I420VideoFrame* cropped_frame) { - cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, - cropped_width, - (cropped_width + 1) / 2, - (cropped_width + 1) / 2); + cropped_frame->set_width(cropped_width); + cropped_frame->set_height(cropped_height); EXPECT_EQ(0, ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, source_height, 0, kRotateNone, cropped_frame)); -- cgit v1.2.3 From fd33293d58aa9e715000477dae3fdc0cfa394f42 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Mon, 2 Mar 2015 13:57:22 +0000 Subject: I420VideoFrame: Remove functions set_width and set_height This is a partial reland of https://webrtc-codereview.appspot.com/39939004/. The functions set_width and set_height in I420VideoFrame are not needed and just add complexity. R=perkj@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/41009004 Cr-Commit-Position: refs/heads/master@{#8556} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8556 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/video_processing_unittest.cc | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 70e19cc26f..5ca2feb07c 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -91,8 +91,6 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. I420VideoFrame videoFrame; - videoFrame.set_width(width_); - videoFrame.set_height(height_); EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); @@ -120,22 +118,21 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { TEST_F(VideoProcessingModuleTest, HandleBadSize) { VideoProcessingModule::FrameStats stats; - video_frame_.ResetSize(); - video_frame_.set_width(width_); - video_frame_.set_height(0); - EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, video_frame_)); + I420VideoFrame bad_frame; + bad_frame.CreateEmptyFrame(width_, 0, width_, (width_ + 1) / 2, + (width_ + 1) / 2); + EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, bad_frame)); - EXPECT_EQ(-1, vpm_->ColorEnhancement(&video_frame_)); + EXPECT_EQ(-1, vpm_->ColorEnhancement(&bad_frame)); - EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); + EXPECT_EQ(-1, vpm_->Deflickering(&bad_frame, &stats)); - EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); + EXPECT_EQ(-3, vpm_->BrightnessDetection(bad_frame, stats)); EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); I420VideoFrame *out_frame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(video_frame_, - &out_frame)); + EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, &out_frame)); } TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { @@ -335,8 +332,9 @@ void CropFrame(const uint8_t* source_data, int cropped_width, int cropped_height, I420VideoFrame* cropped_frame) { - cropped_frame->set_width(cropped_width); - cropped_frame->set_height(cropped_height); + cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, cropped_width, + (cropped_width + 1) / 2, + (cropped_width + 1) / 2); EXPECT_EQ(0, ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, source_height, 0, kRotateNone, cropped_frame)); -- cgit v1.2.3 From 59140d6a5aaabb95beaad20d63f38d8755642940 Mon Sep 17 00:00:00 2001 From: "guoweis@webrtc.org" Date: Mon, 9 Mar 2015 17:07:31 +0000 Subject: Remove VideoRotationMode to VideoRotation. With this change, there is only one copy of rotation enum. BUG=4145 R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48369004 Cr-Commit-Position: refs/heads/master@{#8654} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8654 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/unit_test/brightness_detection_test.cc | 15 +++++------- .../main/test/unit_test/color_enhancement_test.cc | 21 ++++++++--------- .../main/test/unit_test/content_metrics_test.cc | 5 ++-- .../main/test/unit_test/deflickering_test.cc | 6 ++--- .../test/unit_test/video_processing_unittest.cc | 27 +++++++++------------- 5 files changed, 31 insertions(+), 43 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index 69f7fd86d3..8e15d64393 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -23,9 +23,8 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); frameNum++; VideoProcessingModule::FrameStats stats; ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); @@ -51,9 +50,8 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) frame_length_ && frameNum < 300) { - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); frameNum++; uint8_t* frame = video_frame_.buffer(kYPlane); @@ -91,9 +89,8 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_ && frameNum < 300) { - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); frameNum++; uint8_t* y_plane = video_frame_.buffer(kYPlane); diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index 80f230d9fa..4307be3f3e 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -44,9 +44,8 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) frame_length_) { // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); frameNum++; t0 = TickTime::Now(); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&video_frame_)); @@ -91,14 +90,13 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) frame_length_) { // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); ASSERT_EQ(frame_length_, fread(ref_buffer.get(), 1, frame_length_, refFile)); - EXPECT_EQ(0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &refVideoFrame)); + EXPECT_EQ( + 0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, width_, height_, 0, + kVideoRotation_0, &refVideoFrame)); EXPECT_EQ(0, memcmp(video_frame_.buffer(kYPlane), refVideoFrame.buffer(kYPlane), size_y_)); @@ -123,9 +121,8 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) I420VideoFrame testVideoFrame; testVideoFrame.CreateEmptyFrame(width_, height_, width_, half_width_, half_width_); - EXPECT_EQ(0, ConvertToI420(kI420, testFrame.get(), 0, 0, - width_, height_, 0, kRotateNone, - &testVideoFrame)); + EXPECT_EQ(0, ConvertToI420(kI420, testFrame.get(), 0, 0, width_, height_, 0, + kVideoRotation_0, &testVideoFrame)); ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index ca71d551bf..8a2404f8e6 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -27,9 +27,8 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) { while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); _cM_c = ca__c.ComputeContentMetrics(video_frame_); _cM_SSE = ca__sse.ComputeContentMetrics(video_frame_); diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 01e98d13d0..cba1dfc4f8 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -56,9 +56,9 @@ TEST_F(VideoProcessingModuleTest, Deflickering) frame_length_) { frameNum++; - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ( + 0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, + height_, 0, kVideoRotation_0, &video_frame_)); video_frame_.set_timestamp(timeStamp); t0 = TickTime::Now(); diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 5ca2feb07c..60a2e41c4c 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -106,9 +106,8 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); @@ -142,9 +141,8 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_)); ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats)); @@ -156,9 +154,8 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); video_frame2.CopyFrame(video_frame_); ASSERT_EQ(0, vpm_->BrightnessDetection(video_frame_, stats)); @@ -172,9 +169,8 @@ TEST_F(VideoProcessingModuleTest, FrameStats) { rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); EXPECT_FALSE(vpm_->ValidFrameStats(stats)); EXPECT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); @@ -233,9 +229,8 @@ TEST_F(VideoProcessingModuleTest, Resampler) { ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, - width_, height_, - 0, kRotateNone, &video_frame_)); + EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, + 0, kVideoRotation_0, &video_frame_)); // Cropped source frame that will contain the expected visible region. I420VideoFrame cropped_source_frame; cropped_source_frame.CopyFrame(video_frame_); @@ -337,7 +332,7 @@ void CropFrame(const uint8_t* source_data, (cropped_width + 1) / 2); EXPECT_EQ(0, ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, - source_height, 0, kRotateNone, cropped_frame)); + source_height, 0, kVideoRotation_0, cropped_frame)); } void TestSize(const I420VideoFrame& source_frame, -- cgit v1.2.3 From 2dc5fa69b2baef2ece158c9e1285516087faaa53 Mon Sep 17 00:00:00 2001 From: "hbos@webrtc.org" Date: Mon, 16 Mar 2015 13:00:58 +0000 Subject: Changed argument occurences of const I420VideoFrame* to const I420VideoFrame& and non-const I420VideoFrame& to I420VideoFrame*. R=magjed@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/40299004 Cr-Commit-Position: refs/heads/master@{#8731} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8731 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_processing/main/test/unit_test/video_processing_unittest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 60a2e41c4c..1592e376b4 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -130,7 +130,7 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) { EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); - I420VideoFrame *out_frame = NULL; + I420VideoFrame* out_frame = NULL; EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, &out_frame)); } @@ -358,7 +358,7 @@ void TestSize(const I420VideoFrame& source_frame, WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); // Compute PSNR against the cropped source frame and check expectation. - double psnr = I420PSNR(&cropped_source_frame, out_frame); + double psnr = I420PSNR(cropped_source_frame, *out_frame); EXPECT_GT(psnr, expected_psnr); printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " "source which is scaled down/up to: %d %d, and back to source size \n", -- cgit v1.2.3 From 2056ee3e3c7683ae4b2c4b12da99c3105c4f46a9 Mon Sep 17 00:00:00 2001 From: "magjed@webrtc.org" Date: Mon, 16 Mar 2015 13:46:52 +0000 Subject: Revert "Changed argument occurences of const I420VideoFrame* to const I420VideoFrame& and non-const I420VideoFrame& to I420VideoFrame*." This reverts commit r8731. Reason for revert: Breakes Chromium FYI bots. TBR=hbos, tommi Review URL: https://webrtc-codereview.appspot.com/40359004 Cr-Commit-Position: refs/heads/master@{#8733} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8733 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_processing/main/test/unit_test/video_processing_unittest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 1592e376b4..60a2e41c4c 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -130,7 +130,7 @@ TEST_F(VideoProcessingModuleTest, HandleBadSize) { EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); - I420VideoFrame* out_frame = NULL; + I420VideoFrame *out_frame = NULL; EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, &out_frame)); } @@ -358,7 +358,7 @@ void TestSize(const I420VideoFrame& source_frame, WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); // Compute PSNR against the cropped source frame and check expectation. - double psnr = I420PSNR(cropped_source_frame, *out_frame); + double psnr = I420PSNR(&cropped_source_frame, out_frame); EXPECT_GT(psnr, expected_psnr); printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " "source which is scaled down/up to: %d %d, and back to source size \n", -- cgit v1.2.3 From 5a477a0bc6fd3657eb7173d2c8a2e1a01a88dbb3 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Wed, 18 Mar 2015 14:11:39 +0000 Subject: DCHECK frame parameters instead of return codes. We should never be creating video frames without width/height. If these DCHECKs fire we should be fixing the calling code instead. BUG=4359 R=magjed@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/46639004 Cr-Commit-Position: refs/heads/master@{#8779} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8779 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/test/unit_test/video_processing_unittest.cc | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 60a2e41c4c..8d3fcd6531 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -114,26 +114,6 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); } -TEST_F(VideoProcessingModuleTest, HandleBadSize) { - VideoProcessingModule::FrameStats stats; - - I420VideoFrame bad_frame; - bad_frame.CreateEmptyFrame(width_, 0, width_, (width_ + 1) / 2, - (width_ + 1) / 2); - EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, bad_frame)); - - EXPECT_EQ(-1, vpm_->ColorEnhancement(&bad_frame)); - - EXPECT_EQ(-1, vpm_->Deflickering(&bad_frame, &stats)); - - EXPECT_EQ(-3, vpm_->BrightnessDetection(bad_frame, stats)); - - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->SetTargetResolution(0,0,0)); - - I420VideoFrame *out_frame = NULL; - EXPECT_EQ(VPM_PARAMETER_ERROR, vpm_->PreprocessFrame(bad_frame, &out_frame)); -} - TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { I420VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; -- cgit v1.2.3 From 4feb50500d59614b2b62880e77053cb0d0452ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 13 May 2015 11:27:20 +0200 Subject: Remove VideoProcessing::ColorEnhancement. Code for creating this table still (currently) exists under webrtc/modules/video_processing/main/test/unit_test/createTable.m. This processing effect is disabled but still occupies 64k of binary size. BUG=4491 R=marpan@google.com, mflodman@webrtc.org, marpan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/47069004 Cr-Commit-Position: refs/heads/master@{#9183} --- .../main/test/unit_test/color_enhancement_test.cc | 144 --------------------- .../test/unit_test/video_processing_unittest.cc | 2 - 2 files changed, 146 deletions(-) delete mode 100644 webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc deleted file mode 100644 index 4307be3f3e..0000000000 --- a/webrtc/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include - -#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" -#include "webrtc/system_wrappers/interface/tick_util.h" -#include "webrtc/test/testsupport/fileutils.h" - -namespace webrtc { - -TEST_F(VideoProcessingModuleTest, ColorEnhancement) -{ - TickTime t0; - TickTime t1; - TickInterval acc_ticks; - - // Use a shorter version of the Foreman clip for this test. - fclose(source_file_); - const std::string video_file = - webrtc::test::ResourcePath("foreman_cif_short", "yuv"); - source_file_ = fopen(video_file.c_str(), "rb"); - ASSERT_TRUE(source_file_ != NULL) << - "Cannot read source file: " + video_file + "\n"; - - std::string output_file = webrtc::test::OutputPath() + - "foremanColorEnhancedVPM_cif_short.yuv"; - FILE* modFile = fopen(output_file.c_str(), "w+b"); - ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; - - uint32_t frameNum = 0; - rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); - while (fread(video_buffer.get(), 1, frame_length_, source_file_) == - frame_length_) - { - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, - height_, 0, kVideoRotation_0, &video_frame_)); - frameNum++; - t0 = TickTime::Now(); - ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&video_frame_)); - t1 = TickTime::Now(); - acc_ticks += t1 - t0; - if (PrintI420VideoFrame(video_frame_, modFile) < 0) { - return; - } - } - ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; - - printf("\nTime per frame: %d us \n", - static_cast(acc_ticks.Microseconds() / frameNum)); - rewind(modFile); - - printf("Comparing files...\n\n"); - std::string reference_filename = - webrtc::test::ResourcePath("foremanColorEnhanced_cif_short", "yuv"); - FILE* refFile = fopen(reference_filename.c_str(), "rb"); - ASSERT_TRUE(refFile != NULL) << "Cannot open reference file: " << - reference_filename << "\n" - "Create the reference by running Matlab script createTable.m."; - - // get file lenghts - ASSERT_EQ(0, fseek(refFile, 0L, SEEK_END)); - long refLen = ftell(refFile); - ASSERT_NE(-1L, refLen); - rewind(refFile); - ASSERT_EQ(0, fseek(modFile, 0L, SEEK_END)); - long testLen = ftell(modFile); - ASSERT_NE(-1L, testLen); - rewind(modFile); - ASSERT_EQ(refLen, testLen) << "File lengths differ."; - - I420VideoFrame refVideoFrame; - refVideoFrame.CreateEmptyFrame(width_, height_, - width_, half_width_, half_width_); - - // Compare frame-by-frame. - rtc::scoped_ptr ref_buffer(new uint8_t[frame_length_]); - while (fread(video_buffer.get(), 1, frame_length_, modFile) == - frame_length_) - { - // Using ConvertToI420 to add stride to the image. - EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, - height_, 0, kVideoRotation_0, &video_frame_)); - ASSERT_EQ(frame_length_, fread(ref_buffer.get(), 1, frame_length_, - refFile)); - EXPECT_EQ( - 0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, width_, height_, 0, - kVideoRotation_0, &refVideoFrame)); - EXPECT_EQ(0, memcmp(video_frame_.buffer(kYPlane), - refVideoFrame.buffer(kYPlane), - size_y_)); - EXPECT_EQ(0, memcmp(video_frame_.buffer(kUPlane), - refVideoFrame.buffer(kUPlane), - size_uv_)); - EXPECT_EQ(0, memcmp(video_frame_.buffer(kVPlane), - refVideoFrame.buffer(kVPlane), - size_uv_)); - } - ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; - - // Verify that all color pixels are enhanced, and no luminance values are - // altered. - - rtc::scoped_ptr testFrame(new uint8_t[frame_length_]); - - // Use value 128 as probe value, since we know that this will be changed - // in the enhancement. - memset(testFrame.get(), 128, frame_length_); - - I420VideoFrame testVideoFrame; - testVideoFrame.CreateEmptyFrame(width_, height_, - width_, half_width_, half_width_); - EXPECT_EQ(0, ConvertToI420(kI420, testFrame.get(), 0, 0, width_, height_, 0, - kVideoRotation_0, &testVideoFrame)); - - ASSERT_EQ(0, VideoProcessingModule::ColorEnhancement(&testVideoFrame)); - - EXPECT_EQ(0, memcmp(testVideoFrame.buffer(kYPlane), testFrame.get(), - size_y_)) - << "Function is modifying the luminance."; - - EXPECT_NE(0, memcmp(testVideoFrame.buffer(kUPlane), - testFrame.get() + size_y_, size_uv_)) << - "Function is not modifying all chrominance pixels"; - EXPECT_NE(0, memcmp(testVideoFrame.buffer(kVPlane), - testFrame.get() + size_y_ + size_uv_, size_uv_)) << - "Function is not modifying all chrominance pixels"; - - ASSERT_EQ(0, fclose(refFile)); - ASSERT_EQ(0, fclose(modFile)); -} - -} // namespace webrtc diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 8d3fcd6531..6557d0f385 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -94,8 +94,6 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); - EXPECT_EQ(-1, vpm_->ColorEnhancement(&videoFrame)); - EXPECT_EQ(-1, vpm_->Deflickering(&videoFrame, &stats)); EXPECT_EQ(-3, vpm_->BrightnessDetection(videoFrame, stats)); -- cgit v1.2.3 From 7cd16b03b2cdd6ee55a5b9d4ceec679997402245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Thu, 28 May 2015 14:44:28 +0200 Subject: video_processing_unittest: Only create files for visual inspection if the boolean flag 'gen_files' is set. BUG=4648 R=henrik.lundin@webrtc.org, kjellander@webrtc.org, stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/56399004 Cr-Commit-Position: refs/heads/master@{#9313} --- .../main/test/unit_test/video_processing_unittest.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 6557d0f385..ea71890b34 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -12,12 +12,20 @@ #include +#include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { +namespace { + +// Define command line flag 'gen_files' (default value: false). +DEFINE_bool(gen_files, false, "Output files for visual inspection."); + +} // namespace + static void PreprocessFrameAndVerify(const I420VideoFrame& source, int target_width, int target_height, @@ -41,8 +49,8 @@ static void TestSize(const I420VideoFrame& source_frame, int target_height, double expected_psnr, VideoProcessingModule* vpm); -bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); +static bool CompareFrames(const webrtc::I420VideoFrame& frame1, + const webrtc::I420VideoFrame& frame2); static void WriteProcessedFrameForVisualInspection( const I420VideoFrame& source, const I420VideoFrame& processed); @@ -362,6 +370,9 @@ bool CompareFrames(const webrtc::I420VideoFrame& frame1, void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, const I420VideoFrame& processed) { + // Skip if writing to files is not enabled. + if (!FLAGS_gen_files) + return; // Write the processed frame to file for visual inspection. std::ostringstream filename; filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() -- cgit v1.2.3 From 4765070b8d6f024509c717c04d9b708750666927 Mon Sep 17 00:00:00 2001 From: Miguel Casas-Sanchez Date: Fri, 29 May 2015 17:21:40 -0700 Subject: Rename I420VideoFrame to VideoFrame. This is a mechanical change since it affects so many files. I420VideoFrame -> VideoFrame and reformatted. Rationale: in the next CL I420VideoFrame will get an indication of Pixel Format (I420 for starters) and of storage type: usually UNOWNED, could be SHMEM, and in the near future will be possibly TEXTURE. See https://codereview.chromium.org/1154153003 for the change that happened in Cr. BUG=4730, chromium:440843 R=jiayl@webrtc.org, niklas.enbom@webrtc.org, pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/52629004 Cr-Commit-Position: refs/heads/master@{#9339} --- .../main/test/unit_test/deflickering_test.cc | 2 +- .../test/unit_test/video_processing_unittest.cc | 51 +++++++++++----------- .../test/unit_test/video_processing_unittest.h | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index cba1dfc4f8..2a260d2c5c 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -70,7 +70,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) if (run_idx == 0) { - if (PrintI420VideoFrame(video_frame_, deflickerFile) < 0) { + if (PrintVideoFrame(video_frame_, deflickerFile) < 0) { return; } } diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index ea71890b34..e17223fd8e 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -26,11 +26,11 @@ DEFINE_bool(gen_files, false, "Output files for visual inspection."); } // namespace -static void PreprocessFrameAndVerify(const I420VideoFrame& source, +static void PreprocessFrameAndVerify(const VideoFrame& source, int target_width, int target_height, VideoProcessingModule* vpm, - I420VideoFrame** out_frame); + VideoFrame** out_frame); static void CropFrame(const uint8_t* source_data, int source_width, int source_height, @@ -38,22 +38,21 @@ static void CropFrame(const uint8_t* source_data, int offset_y, int cropped_width, int cropped_height, - I420VideoFrame* cropped_frame); + VideoFrame* cropped_frame); // The |source_data| is cropped and scaled to |target_width| x |target_height|, // and then scaled back to the expected cropped size. |expected_psnr| is used to // verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR // verified under the same conditions. -static void TestSize(const I420VideoFrame& source_frame, - const I420VideoFrame& cropped_source_frame, +static void TestSize(const VideoFrame& source_frame, + const VideoFrame& cropped_source_frame, int target_width, int target_height, double expected_psnr, VideoProcessingModule* vpm); -static bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2); -static void WriteProcessedFrameForVisualInspection( - const I420VideoFrame& source, - const I420VideoFrame& processed); +static bool CompareFrames(const webrtc::VideoFrame& frame1, + const webrtc::VideoFrame& frame2); +static void WriteProcessedFrameForVisualInspection(const VideoFrame& source, + const VideoFrame& processed); VideoProcessingModuleTest::VideoProcessingModuleTest() : vpm_(NULL), @@ -98,7 +97,7 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { // TODO(mikhal/stefan): Do we need this one? VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. - I420VideoFrame videoFrame; + VideoFrame videoFrame; EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); @@ -121,7 +120,7 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { } TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { - I420VideoFrame video_frame2; + VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); @@ -184,7 +183,7 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { // Disable spatial sampling. vpm_->SetInputFrameResampleMode(kNoRescaling); EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); - I420VideoFrame* out_frame = NULL; + VideoFrame* out_frame = NULL; // Set rescaling => output frame != NULL. vpm_->SetInputFrameResampleMode(kFastRescaling); PreprocessFrameAndVerify(video_frame_, resolution, resolution, vpm_, @@ -218,7 +217,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 0, kVideoRotation_0, &video_frame_)); // Cropped source frame that will contain the expected visible region. - I420VideoFrame cropped_source_frame; + VideoFrame cropped_source_frame; cropped_source_frame.CopyFrame(video_frame_); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { @@ -283,11 +282,11 @@ TEST_F(VideoProcessingModuleTest, Resampler) { static_cast(min_runtime)); } -void PreprocessFrameAndVerify(const I420VideoFrame& source, +void PreprocessFrameAndVerify(const VideoFrame& source, int target_width, int target_height, VideoProcessingModule* vpm, - I420VideoFrame** out_frame) { + VideoFrame** out_frame) { ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source, out_frame)); @@ -312,7 +311,7 @@ void CropFrame(const uint8_t* source_data, int offset_y, int cropped_width, int cropped_height, - I420VideoFrame* cropped_frame) { + VideoFrame* cropped_frame) { cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, cropped_width, (cropped_width + 1) / 2, (cropped_width + 1) / 2); @@ -321,14 +320,14 @@ void CropFrame(const uint8_t* source_data, source_height, 0, kVideoRotation_0, cropped_frame)); } -void TestSize(const I420VideoFrame& source_frame, - const I420VideoFrame& cropped_source_frame, +void TestSize(const VideoFrame& source_frame, + const VideoFrame& cropped_source_frame, int target_width, int target_height, double expected_psnr, VideoProcessingModule* vpm) { // Resample source_frame to out_frame. - I420VideoFrame* out_frame = NULL; + VideoFrame* out_frame = NULL; vpm->SetInputFrameResampleMode(kBox); PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, &out_frame); @@ -337,7 +336,7 @@ void TestSize(const I420VideoFrame& source_frame, WriteProcessedFrameForVisualInspection(source_frame, *out_frame); // Scale |resampled_source_frame| back to the source scale. - I420VideoFrame resampled_source_frame; + VideoFrame resampled_source_frame; resampled_source_frame.CopyFrame(*out_frame); PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), cropped_source_frame.height(), vpm, &out_frame); @@ -352,8 +351,8 @@ void TestSize(const I420VideoFrame& source_frame, target_width, target_height); } -bool CompareFrames(const webrtc::I420VideoFrame& frame1, - const webrtc::I420VideoFrame& frame2) { +bool CompareFrames(const webrtc::VideoFrame& frame1, + const webrtc::VideoFrame& frame2) { for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { webrtc::PlaneType plane_type = static_cast(plane); int allocated_size1 = frame1.allocated_size(plane_type); @@ -368,8 +367,8 @@ bool CompareFrames(const webrtc::I420VideoFrame& frame1, return true; } -void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, - const I420VideoFrame& processed) { +void WriteProcessedFrameForVisualInspection(const VideoFrame& source, + const VideoFrame& processed) { // Skip if writing to files is not enabled. if (!FLAGS_gen_files) return; @@ -381,7 +380,7 @@ void WriteProcessedFrameForVisualInspection(const I420VideoFrame& source, std::cout << "Watch " << filename.str() << " and verify that it is okay." << std::endl; FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); - if (PrintI420VideoFrame(processed, stand_alone_file) < 0) + if (PrintVideoFrame(processed, stand_alone_file) < 0) std::cerr << "Failed to write: " << filename.str() << std::endl; if (stand_alone_file) fclose(stand_alone_file); diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h index 37e2c02b94..01a5161c33 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h @@ -33,7 +33,7 @@ class VideoProcessingModuleTest : public ::testing::Test { } VideoProcessingModule* vpm_; FILE* source_file_; - I420VideoFrame video_frame_; + VideoFrame video_frame_; const int width_; const int half_width_; const int height_; -- cgit v1.2.3 From a2c79405b407162119954d57855c8c04c043df76 Mon Sep 17 00:00:00 2001 From: henrika Date: Wed, 10 Jun 2015 13:24:48 +0200 Subject: Ensures that modules_unittests runs on iOS BUG=4752 R=tkchin@chromium.org Review URL: https://codereview.webrtc.org/1171033002. Cr-Commit-Position: refs/heads/master@{#9408} --- .../main/test/unit_test/brightness_detection_test.cc | 3 ++- .../main/test/unit_test/content_metrics_test.cc | 3 ++- .../main/test/unit_test/deflickering_test.cc | 3 ++- .../main/test/unit_test/video_processing_unittest.cc | 13 +++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index 8e15d64393..4d0de3ac98 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -11,10 +11,11 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" +#include "webrtc/test/testsupport/gtest_disable.h" using namespace webrtc; -TEST_F(VideoProcessingModuleTest, BrightnessDetection) +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(BrightnessDetection)) { uint32_t frameNum = 0; int32_t brightnessWarning = 0; diff --git a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 8a2404f8e6..d9c1309d9b 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -12,10 +12,11 @@ #include "webrtc/modules/video_processing/main/interface/video_processing.h" #include "webrtc/modules/video_processing/main/source/content_analysis.h" #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" +#include "webrtc/test/testsupport/gtest_disable.h" namespace webrtc { -TEST_F(VideoProcessingModuleTest, ContentAnalysis) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(ContentAnalysis)) { VPMContentAnalysis ca__c(false); VPMContentAnalysis ca__sse(true); VideoContentMetrics *_cM_c, *_cM_SSE; diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index 2a260d2c5c..f270813078 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -16,10 +16,11 @@ #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" +#include "webrtc/test/testsupport/gtest_disable.h" namespace webrtc { -TEST_F(VideoProcessingModuleTest, Deflickering) +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(Deflickering)) { enum { NumRuns = 30 }; uint32_t frameNum = 0; diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index e17223fd8e..5e74ec02e3 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -16,6 +16,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" +#include "webrtc/test/testsupport/gtest_disable.h" namespace webrtc { @@ -93,7 +94,7 @@ void VideoProcessingModuleTest::TearDown() { vpm_ = NULL; } -TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(HandleNullBuffer)) { // TODO(mikhal/stefan): Do we need this one? VideoProcessingModule::FrameStats stats; // Video frame with unallocated buffer. @@ -106,7 +107,7 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { EXPECT_EQ(-3, vpm_->BrightnessDetection(videoFrame, stats)); } -TEST_F(VideoProcessingModuleTest, HandleBadStats) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(HandleBadStats)) { VideoProcessingModule::FrameStats stats; rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, @@ -119,7 +120,7 @@ TEST_F(VideoProcessingModuleTest, HandleBadStats) { EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); } -TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) { VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. @@ -149,7 +150,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); } -TEST_F(VideoProcessingModuleTest, FrameStats) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(FrameStats)) { VideoProcessingModule::FrameStats stats; rtc::scoped_ptr video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, @@ -174,7 +175,7 @@ TEST_F(VideoProcessingModuleTest, FrameStats) { EXPECT_FALSE(vpm_->ValidFrameStats(stats)); } -TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(PreprocessorLogic)) { // Disable temporal sampling (frame dropping). vpm_->EnableTemporalDecimation(false); int resolution = 100; @@ -194,7 +195,7 @@ TEST_F(VideoProcessingModuleTest, PreprocessorLogic) { EXPECT_TRUE(out_frame == NULL); } -TEST_F(VideoProcessingModuleTest, Resampler) { +TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(Resampler)) { enum { NumRuns = 1 }; int64_t min_runtime = 0; -- cgit v1.2.3 From f4aa4c2283c1c85f0e69aad69355889a66e99388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Fri, 18 Sep 2015 12:24:25 +0200 Subject: Remove id from VideoProcessingModule. Also converts CriticalSectionWrapper to rtc::CriticalSection as a bonus. BUG=webrtc:1695 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/1346643002 . Cr-Commit-Position: refs/heads/master@{#9986} --- .../video_processing/main/test/unit_test/video_processing_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 5e74ec02e3..99984fa002 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -66,7 +66,7 @@ VideoProcessingModuleTest::VideoProcessingModuleTest() frame_length_(CalcBufferSize(kI420, width_, height_)) {} void VideoProcessingModuleTest::SetUp() { - vpm_ = VideoProcessingModule::Create(0); + vpm_ = VideoProcessingModule::Create(); ASSERT_TRUE(vpm_ != NULL); ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, -- cgit v1.2.3 From 98f53510b222f71fdd8b799b2f33737ceeb28c61 Mon Sep 17 00:00:00 2001 From: Henrik Kjellander Date: Wed, 28 Oct 2015 18:17:40 +0100 Subject: system_wrappers: rename interface -> include BUG=webrtc:5095 R=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1413333002 . Cr-Commit-Position: refs/heads/master@{#10438} --- .../modules/video_processing/main/test/unit_test/deflickering_test.cc | 2 +- .../video_processing/main/test/unit_test/video_processing_unittest.cc | 2 +- .../video_processing/main/test/unit_test/video_processing_unittest.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'webrtc/modules/video_processing/main/test/unit_test') diff --git a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc index f270813078..83d09ef486 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -14,7 +14,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" -#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/gtest_disable.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 99984fa002..11ccc4891b 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -14,7 +14,7 @@ #include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/gtest_disable.h" diff --git a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h index 01a5161c33..4a4fda41e6 100644 --- a/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h +++ b/webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h @@ -13,7 +13,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/modules/video_processing/main/interface/video_processing.h" -#include "webrtc/system_wrappers/interface/trace.h" +#include "webrtc/system_wrappers/include/trace.h" #include "webrtc/test/testsupport/fileutils.h" namespace webrtc { -- cgit v1.2.3