1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* 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 <memory>
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_processing/include/video_processing.h"
#include "webrtc/modules/video_processing/test/video_processing_unittest.h"
namespace webrtc {
#if defined(WEBRTC_IOS)
#define MAYBE_BrightnessDetection DISABLED_BrightnessDetection
#else
#define MAYBE_BrightnessDetection BrightnessDetection
#endif
TEST_F(VideoProcessingTest, MAYBE_BrightnessDetection) {
uint32_t frameNum = 0;
int32_t brightnessWarning = 0;
uint32_t warningCount = 0;
std::unique_ptr<uint8_t[]> 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, kVideoRotation_0, &video_frame_));
frameNum++;
VideoProcessing::FrameStats stats;
vp_->GetFrameStats(video_frame_, &stats);
EXPECT_GT(stats.num_pixels, 0u);
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
0);
if (brightnessWarning != VideoProcessing::kNoWarning) {
warningCount++;
}
}
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
// 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);
rewind(source_file_);
frameNum = 0;
warningCount = 0;
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, kVideoRotation_0, &video_frame_));
frameNum++;
uint8_t* frame = video_frame_.buffer(kYPlane);
uint32_t yTmp = 0;
for (int yIdx = 0; yIdx < width_ * height_; yIdx++) {
yTmp = frame[yIdx] << 1;
if (yTmp > 255) {
yTmp = 255;
}
frame[yIdx] = static_cast<uint8_t>(yTmp);
}
VideoProcessing::FrameStats stats;
vp_->GetFrameStats(video_frame_, &stats);
EXPECT_GT(stats.num_pixels, 0u);
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
0);
EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning);
if (brightnessWarning == VideoProcessing::kBrightWarning) {
warningCount++;
}
}
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
// Expect many brightness warnings
warningProportion = static_cast<float>(warningCount) / frameNum * 100;
printf("Bright foreman: %.1f %%\n", warningProportion);
EXPECT_GT(warningProportion, 95);
rewind(source_file_);
frameNum = 0;
warningCount = 0;
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, kVideoRotation_0, &video_frame_));
frameNum++;
uint8_t* y_plane = video_frame_.buffer(kYPlane);
int32_t yTmp = 0;
for (int yIdx = 0; yIdx < width_ * height_; yIdx++) {
yTmp = y_plane[yIdx] >> 1;
y_plane[yIdx] = static_cast<uint8_t>(yTmp);
}
VideoProcessing::FrameStats stats;
vp_->GetFrameStats(video_frame_, &stats);
EXPECT_GT(stats.num_pixels, 0u);
ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats),
0);
EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning);
if (brightnessWarning == VideoProcessing::kDarkWarning) {
warningCount++;
}
}
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
// Expect many darkness warnings
warningProportion = static_cast<float>(warningCount) / frameNum * 100;
printf("Dark foreman: %.1f %%\n\n", warningProportion);
EXPECT_GT(warningProportion, 90);
}
} // namespace webrtc
|