Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: webrtc/modules/video_processing/test/brightness_detection_test.cc

Issue 1482913003: Initial VideoProcessing refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More lint. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 using namespace webrtc; 16 namespace webrtc {
17 17
18 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(BrightnessDetection)) 18 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(BrightnessDetection)) {
19 {
20 uint32_t frameNum = 0; 19 uint32_t frameNum = 0;
21 int32_t brightnessWarning = 0; 20 int32_t brightnessWarning = 0;
22 uint32_t warningCount = 0; 21 uint32_t warningCount = 0;
23 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_]);
24 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == 23 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
25 frame_length_) 24 frame_length_) {
26 {
27 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, 25 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
pbos-webrtc 2015/11/30 11:51:57 If you wanna, can you clang format the entire file
28 height_, 0, kVideoRotation_0, &video_frame_)); 26 height_, 0, kVideoRotation_0, &video_frame_));
29 frameNum++; 27 frameNum++;
30 VideoProcessingModule::FrameStats stats; 28 VideoProcessing::FrameStats stats;
31 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 29 ASSERT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
32 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, 30 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
33 stats), 0); 31 stats), 0);
34 if (brightnessWarning != VideoProcessingModule::kNoWarning) 32 if (brightnessWarning != VideoProcessing::kNoWarning) {
35 {
36 warningCount++; 33 warningCount++;
37 } 34 }
38 } 35 }
39 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; 36 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
40 37
41 // Expect few warnings 38 // Expect few warnings
42 float warningProportion = static_cast<float>(warningCount) / frameNum * 100; 39 float warningProportion = static_cast<float>(warningCount) / frameNum * 100;
43 printf("\nWarning proportions:\n"); 40 printf("\nWarning proportions:\n");
44 printf("Stock foreman: %.1f %%\n", warningProportion); 41 printf("Stock foreman: %.1f %%\n", warningProportion);
45 EXPECT_LT(warningProportion, 10); 42 EXPECT_LT(warningProportion, 10);
46 43
47 rewind(source_file_); 44 rewind(source_file_);
48 frameNum = 0; 45 frameNum = 0;
49 warningCount = 0; 46 warningCount = 0;
50 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == 47 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
51 frame_length_ && 48 frame_length_ &&
52 frameNum < 300) 49 frameNum < 300) {
53 {
54 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, 50 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
55 height_, 0, kVideoRotation_0, &video_frame_)); 51 height_, 0, kVideoRotation_0, &video_frame_));
56 frameNum++; 52 frameNum++;
57 53
58 uint8_t* frame = video_frame_.buffer(kYPlane); 54 uint8_t* frame = video_frame_.buffer(kYPlane);
59 uint32_t yTmp = 0; 55 uint32_t yTmp = 0;
60 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) 56 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) {
61 {
62 yTmp = frame[yIdx] << 1; 57 yTmp = frame[yIdx] << 1;
63 if (yTmp > 255) 58 if (yTmp > 255) {
64 {
65 yTmp = 255; 59 yTmp = 255;
66 } 60 }
67 frame[yIdx] = static_cast<uint8_t>(yTmp); 61 frame[yIdx] = static_cast<uint8_t>(yTmp);
68 } 62 }
69 63
70 VideoProcessingModule::FrameStats stats; 64 VideoProcessing::FrameStats stats;
71 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 65 ASSERT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
72 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, 66 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
73 stats), 0); 67 stats), 0);
74 EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning); 68 EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning);
75 if (brightnessWarning == VideoProcessingModule::kBrightWarning) 69 if (brightnessWarning == VideoProcessing::kBrightWarning) {
76 {
77 warningCount++; 70 warningCount++;
78 } 71 }
79 } 72 }
80 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; 73 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
81 74
82 // Expect many brightness warnings 75 // Expect many brightness warnings
83 warningProportion = static_cast<float>(warningCount) / frameNum * 100; 76 warningProportion = static_cast<float>(warningCount) / frameNum * 100;
84 printf("Bright foreman: %.1f %%\n", warningProportion); 77 printf("Bright foreman: %.1f %%\n", warningProportion);
85 EXPECT_GT(warningProportion, 95); 78 EXPECT_GT(warningProportion, 95);
86 79
87 rewind(source_file_); 80 rewind(source_file_);
88 frameNum = 0; 81 frameNum = 0;
89 warningCount = 0; 82 warningCount = 0;
90 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == 83 while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
91 frame_length_ && frameNum < 300) 84 frame_length_ && frameNum < 300) {
92 {
93 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, 85 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
94 height_, 0, kVideoRotation_0, &video_frame_)); 86 height_, 0, kVideoRotation_0, &video_frame_));
95 frameNum++; 87 frameNum++;
96 88
97 uint8_t* y_plane = video_frame_.buffer(kYPlane); 89 uint8_t* y_plane = video_frame_.buffer(kYPlane);
98 int32_t yTmp = 0; 90 int32_t yTmp = 0;
99 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) 91 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) {
100 {
101 yTmp = y_plane[yIdx] >> 1; 92 yTmp = y_plane[yIdx] >> 1;
102 y_plane[yIdx] = static_cast<uint8_t>(yTmp); 93 y_plane[yIdx] = static_cast<uint8_t>(yTmp);
103 } 94 }
104 95
105 VideoProcessingModule::FrameStats stats; 96 VideoProcessing::FrameStats stats;
106 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 97 ASSERT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
107 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, 98 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_,
108 stats), 0); 99 stats), 0);
109 EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning); 100 EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning);
110 if (brightnessWarning == VideoProcessingModule::kDarkWarning) 101 if (brightnessWarning == VideoProcessing::kDarkWarning) {
111 {
112 warningCount++; 102 warningCount++;
113 } 103 }
114 } 104 }
115 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; 105 ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
116 106
117 // Expect many darkness warnings 107 // Expect many darkness warnings
118 warningProportion = static_cast<float>(warningCount) / frameNum * 100; 108 warningProportion = static_cast<float>(warningCount) / frameNum * 100;
119 printf("Dark foreman: %.1f %%\n\n", warningProportion); 109 printf("Dark foreman: %.1f %%\n\n", warningProportion);
120 EXPECT_GT(warningProportion, 90); 110 EXPECT_GT(warningProportion, 90);
121 } 111 }
112 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698