OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
12 #include "webrtc/modules/video_processing/include/video_processing.h" | 12 #include "webrtc/modules/video_processing/include/video_processing.h" |
13 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" | 13 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" |
14 #include "webrtc/test/testsupport/gtest_disable.h" | 14 #include "webrtc/test/testsupport/gtest_disable.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) { | 18 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) { |
19 uint32_t frameNum = 0; | 19 uint32_t frameNum = 0; |
20 int32_t brightnessWarning = 0; | 20 int32_t brightnessWarning = 0; |
21 uint32_t warningCount = 0; | 21 uint32_t warningCount = 0; |
22 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 22 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
23 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 23 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
24 frame_length_) { | 24 frame_length_) { |
25 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 25 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
26 height_, 0, kVideoRotation_0, &video_frame_)); | 26 0, kVideoRotation_0, &video_frame_)); |
27 frameNum++; | 27 frameNum++; |
28 VideoProcessing::FrameStats stats; | 28 VideoProcessing::FrameStats stats; |
29 vp_->GetFrameStats(video_frame_, &stats); | 29 vp_->GetFrameStats(video_frame_, &stats); |
30 EXPECT_GT(stats.num_pixels, 0u); | 30 EXPECT_GT(stats.num_pixels, 0u); |
31 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, | 31 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats), |
32 stats), 0); | 32 0); |
33 if (brightnessWarning != VideoProcessing::kNoWarning) { | 33 if (brightnessWarning != VideoProcessing::kNoWarning) { |
34 warningCount++; | 34 warningCount++; |
35 } | |
36 } | 35 } |
37 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 36 } |
| 37 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
38 | 38 |
39 // Expect few warnings | 39 // Expect few warnings |
40 float warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 40 float warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
41 printf("\nWarning proportions:\n"); | 41 printf("\nWarning proportions:\n"); |
42 printf("Stock foreman: %.1f %%\n", warningProportion); | 42 printf("Stock foreman: %.1f %%\n", warningProportion); |
43 EXPECT_LT(warningProportion, 10); | 43 EXPECT_LT(warningProportion, 10); |
44 | 44 |
45 rewind(source_file_); | 45 rewind(source_file_); |
46 frameNum = 0; | 46 frameNum = 0; |
47 warningCount = 0; | 47 warningCount = 0; |
48 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 48 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
49 frame_length_ && | 49 frame_length_ && |
50 frameNum < 300) { | 50 frameNum < 300) { |
51 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 51 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
52 height_, 0, kVideoRotation_0, &video_frame_)); | 52 0, kVideoRotation_0, &video_frame_)); |
53 frameNum++; | 53 frameNum++; |
54 | 54 |
55 uint8_t* frame = video_frame_.buffer(kYPlane); | 55 uint8_t* frame = video_frame_.buffer(kYPlane); |
56 uint32_t yTmp = 0; | 56 uint32_t yTmp = 0; |
57 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { | 57 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { |
58 yTmp = frame[yIdx] << 1; | 58 yTmp = frame[yIdx] << 1; |
59 if (yTmp > 255) { | 59 if (yTmp > 255) { |
60 yTmp = 255; | 60 yTmp = 255; |
61 } | 61 } |
62 frame[yIdx] = static_cast<uint8_t>(yTmp); | 62 frame[yIdx] = static_cast<uint8_t>(yTmp); |
63 } | 63 } |
64 | 64 |
65 VideoProcessing::FrameStats stats; | 65 VideoProcessing::FrameStats stats; |
66 vp_->GetFrameStats(video_frame_, &stats); | 66 vp_->GetFrameStats(video_frame_, &stats); |
67 EXPECT_GT(stats.num_pixels, 0u); | 67 EXPECT_GT(stats.num_pixels, 0u); |
68 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, | 68 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats), |
69 stats), 0); | 69 0); |
70 EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning); | 70 EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning); |
71 if (brightnessWarning == VideoProcessing::kBrightWarning) { | 71 if (brightnessWarning == VideoProcessing::kBrightWarning) { |
72 warningCount++; | 72 warningCount++; |
73 } | |
74 } | 73 } |
75 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 74 } |
| 75 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
76 | 76 |
77 // Expect many brightness warnings | 77 // Expect many brightness warnings |
78 warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 78 warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
79 printf("Bright foreman: %.1f %%\n", warningProportion); | 79 printf("Bright foreman: %.1f %%\n", warningProportion); |
80 EXPECT_GT(warningProportion, 95); | 80 EXPECT_GT(warningProportion, 95); |
81 | 81 |
82 rewind(source_file_); | 82 rewind(source_file_); |
83 frameNum = 0; | 83 frameNum = 0; |
84 warningCount = 0; | 84 warningCount = 0; |
85 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 85 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
86 frame_length_ && frameNum < 300) { | 86 frame_length_ && |
87 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 87 frameNum < 300) { |
88 height_, 0, kVideoRotation_0, &video_frame_)); | 88 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
89 frameNum++; | 89 0, kVideoRotation_0, &video_frame_)); |
| 90 frameNum++; |
90 | 91 |
91 uint8_t* y_plane = video_frame_.buffer(kYPlane); | 92 uint8_t* y_plane = video_frame_.buffer(kYPlane); |
92 int32_t yTmp = 0; | 93 int32_t yTmp = 0; |
93 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { | 94 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { |
94 yTmp = y_plane[yIdx] >> 1; | 95 yTmp = y_plane[yIdx] >> 1; |
95 y_plane[yIdx] = static_cast<uint8_t>(yTmp); | 96 y_plane[yIdx] = static_cast<uint8_t>(yTmp); |
96 } | 97 } |
97 | 98 |
98 VideoProcessing::FrameStats stats; | 99 VideoProcessing::FrameStats stats; |
99 vp_->GetFrameStats(video_frame_, &stats); | 100 vp_->GetFrameStats(video_frame_, &stats); |
100 EXPECT_GT(stats.num_pixels, 0u); | 101 EXPECT_GT(stats.num_pixels, 0u); |
101 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, | 102 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, stats), |
102 stats), 0); | 103 0); |
103 EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning); | 104 EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning); |
104 if (brightnessWarning == VideoProcessing::kDarkWarning) { | 105 if (brightnessWarning == VideoProcessing::kDarkWarning) { |
105 warningCount++; | 106 warningCount++; |
106 } | |
107 } | 107 } |
108 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 108 } |
| 109 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
109 | 110 |
110 // Expect many darkness warnings | 111 // Expect many darkness warnings |
111 warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 112 warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
112 printf("Dark foreman: %.1f %%\n\n", warningProportion); | 113 printf("Dark foreman: %.1f %%\n\n", warningProportion); |
113 EXPECT_GT(warningProportion, 90); | 114 EXPECT_GT(warningProportion, 90); |
114 } | 115 } |
115 } // namespace webrtc | 116 } // namespace webrtc |
OLD | NEW |