2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-01-08 19:19:59 +00:00
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
2015-11-18 22:31:24 +01:00
|
|
|
#include "webrtc/modules/video_processing/include/video_processing.h"
|
|
|
|
|
#include "webrtc/modules/video_processing/test/video_processing_unittest.h"
|
2015-06-10 13:24:48 +02:00
|
|
|
#include "webrtc/test/testsupport/gtest_disable.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
using namespace webrtc;
|
|
|
|
|
|
2015-06-10 13:24:48 +02:00
|
|
|
TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(BrightnessDetection))
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2013-04-09 13:38:10 +00:00
|
|
|
uint32_t frameNum = 0;
|
|
|
|
|
int32_t brightnessWarning = 0;
|
|
|
|
|
uint32_t warningCount = 0;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
2013-10-03 16:42:41 +00:00
|
|
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
|
|
|
|
frame_length_)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2015-03-09 17:07:31 +00:00
|
|
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
|
|
|
|
height_, 0, kVideoRotation_0, &video_frame_));
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum++;
|
|
|
|
|
VideoProcessingModule::FrameStats stats;
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
|
|
|
|
|
ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
|
2012-10-19 15:43:31 +00:00
|
|
|
stats), 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (brightnessWarning != VideoProcessingModule::kNoWarning)
|
|
|
|
|
{
|
|
|
|
|
warningCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Expect few warnings
|
|
|
|
|
float warningProportion = static_cast<float>(warningCount) / frameNum * 100;
|
|
|
|
|
printf("\nWarning proportions:\n");
|
|
|
|
|
printf("Stock foreman: %.1f %%\n", warningProportion);
|
|
|
|
|
EXPECT_LT(warningProportion, 10);
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
rewind(source_file_);
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum = 0;
|
|
|
|
|
warningCount = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
|
|
|
|
frame_length_ &&
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum < 300)
|
|
|
|
|
{
|
2015-03-09 17:07:31 +00:00
|
|
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
|
|
|
|
height_, 0, kVideoRotation_0, &video_frame_));
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum++;
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
uint8_t* frame = video_frame_.buffer(kYPlane);
|
2013-04-09 13:38:10 +00:00
|
|
|
uint32_t yTmp = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
for (int yIdx = 0; yIdx < width_ * height_; yIdx++)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
yTmp = frame[yIdx] << 1;
|
|
|
|
|
if (yTmp > 255)
|
|
|
|
|
{
|
|
|
|
|
yTmp = 255;
|
|
|
|
|
}
|
2013-04-09 13:38:10 +00:00
|
|
|
frame[yIdx] = static_cast<uint8_t>(yTmp);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoProcessingModule::FrameStats stats;
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
|
|
|
|
|
ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
|
2012-10-19 15:43:31 +00:00
|
|
|
stats), 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning);
|
|
|
|
|
if (brightnessWarning == VideoProcessingModule::kBrightWarning)
|
|
|
|
|
{
|
|
|
|
|
warningCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Expect many brightness warnings
|
|
|
|
|
warningProportion = static_cast<float>(warningCount) / frameNum * 100;
|
|
|
|
|
printf("Bright foreman: %.1f %%\n", warningProportion);
|
|
|
|
|
EXPECT_GT(warningProportion, 95);
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
rewind(source_file_);
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum = 0;
|
|
|
|
|
warningCount = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
|
|
|
|
frame_length_ && frameNum < 300)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2015-03-09 17:07:31 +00:00
|
|
|
EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
|
|
|
|
height_, 0, kVideoRotation_0, &video_frame_));
|
2011-07-07 08:21:25 +00:00
|
|
|
frameNum++;
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
uint8_t* y_plane = video_frame_.buffer(kYPlane);
|
2013-04-09 13:38:10 +00:00
|
|
|
int32_t yTmp = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
for (int yIdx = 0; yIdx < width_ * height_; yIdx++)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-10-24 18:33:04 +00:00
|
|
|
yTmp = y_plane[yIdx] >> 1;
|
2013-04-09 13:38:10 +00:00
|
|
|
y_plane[yIdx] = static_cast<uint8_t>(yTmp);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoProcessingModule::FrameStats stats;
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
|
|
|
|
|
ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
|
2012-10-19 15:43:31 +00:00
|
|
|
stats), 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning);
|
|
|
|
|
if (brightnessWarning == VideoProcessingModule::kDarkWarning)
|
|
|
|
|
{
|
|
|
|
|
warningCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Expect many darkness warnings
|
|
|
|
|
warningProportion = static_cast<float>(warningCount) / frameNum * 100;
|
|
|
|
|
printf("Dark foreman: %.1f %%\n\n", warningProportion);
|
|
|
|
|
EXPECT_GT(warningProportion, 90);
|
|
|
|
|
}
|