2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
12 #include "webrtc/modules/video_processing/main/interface/video_processing.h"
13 #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h"
15 using namespace webrtc;
17 TEST_F(VideoProcessingModuleTest, BrightnessDetection)
19 uint32_t frameNum = 0;
20 int32_t brightnessWarning = 0;
21 uint32_t warningCount = 0;
22 scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
23 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
26 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0,
28 0, kRotateNone, &video_frame_));
30 VideoProcessingModule::FrameStats stats;
31 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
32 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
34 if (brightnessWarning != VideoProcessingModule::kNoWarning)
39 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
41 // Expect few warnings
42 float warningProportion = static_cast<float>(warningCount) / frameNum * 100;
43 printf("\nWarning proportions:\n");
44 printf("Stock foreman: %.1f %%\n", warningProportion);
45 EXPECT_LT(warningProportion, 10);
50 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
54 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0,
56 0, kRotateNone, &video_frame_));
59 uint8_t* frame = video_frame_.buffer(kYPlane);
61 for (int yIdx = 0; yIdx < width_ * height_; yIdx++)
63 yTmp = frame[yIdx] << 1;
68 frame[yIdx] = static_cast<uint8_t>(yTmp);
71 VideoProcessingModule::FrameStats stats;
72 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
73 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
75 EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning);
76 if (brightnessWarning == VideoProcessingModule::kBrightWarning)
81 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
83 // Expect many brightness warnings
84 warningProportion = static_cast<float>(warningCount) / frameNum * 100;
85 printf("Bright foreman: %.1f %%\n", warningProportion);
86 EXPECT_GT(warningProportion, 95);
91 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
92 frame_length_ && frameNum < 300)
94 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0,
96 0, kRotateNone, &video_frame_));
99 uint8_t* y_plane = video_frame_.buffer(kYPlane);
101 for (int yIdx = 0; yIdx < width_ * height_; yIdx++)
103 yTmp = y_plane[yIdx] >> 1;
104 y_plane[yIdx] = static_cast<uint8_t>(yTmp);
107 VideoProcessingModule::FrameStats stats;
108 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
109 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_,
111 EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning);
112 if (brightnessWarning == VideoProcessingModule::kDarkWarning)
117 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
119 // Expect many darkness warnings
120 warningProportion = static_cast<float>(warningCount) / frameNum * 100;
121 printf("Dark foreman: %.1f %%\n\n", warningProportion);
122 EXPECT_GT(warningProportion, 90);