| 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 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_, |
| 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 vp_->GetFrameStats(video_frame_, &stats); |
| 32 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, | 30 EXPECT_GT(stats.num_pixels, 0u); |
| 31 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, |
| 33 stats), 0); | 32 stats), 0); |
| 34 if (brightnessWarning != VideoProcessingModule::kNoWarning) | 33 if (brightnessWarning != VideoProcessing::kNoWarning) { |
| 35 { | |
| 36 warningCount++; | 34 warningCount++; |
| 37 } | 35 } |
| 38 } | 36 } |
| 39 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 37 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
| 40 | 38 |
| 41 // Expect few warnings | 39 // Expect few warnings |
| 42 float warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 40 float warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
| 43 printf("\nWarning proportions:\n"); | 41 printf("\nWarning proportions:\n"); |
| 44 printf("Stock foreman: %.1f %%\n", warningProportion); | 42 printf("Stock foreman: %.1f %%\n", warningProportion); |
| 45 EXPECT_LT(warningProportion, 10); | 43 EXPECT_LT(warningProportion, 10); |
| 46 | 44 |
| 47 rewind(source_file_); | 45 rewind(source_file_); |
| 48 frameNum = 0; | 46 frameNum = 0; |
| 49 warningCount = 0; | 47 warningCount = 0; |
| 50 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 48 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
| 51 frame_length_ && | 49 frame_length_ && |
| 52 frameNum < 300) | 50 frameNum < 300) { |
| 53 { | |
| 54 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 51 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, |
| 55 height_, 0, kVideoRotation_0, &video_frame_)); | 52 height_, 0, kVideoRotation_0, &video_frame_)); |
| 56 frameNum++; | 53 frameNum++; |
| 57 | 54 |
| 58 uint8_t* frame = video_frame_.buffer(kYPlane); | 55 uint8_t* frame = video_frame_.buffer(kYPlane); |
| 59 uint32_t yTmp = 0; | 56 uint32_t yTmp = 0; |
| 60 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) | 57 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { |
| 61 { | |
| 62 yTmp = frame[yIdx] << 1; | 58 yTmp = frame[yIdx] << 1; |
| 63 if (yTmp > 255) | 59 if (yTmp > 255) { |
| 64 { | |
| 65 yTmp = 255; | 60 yTmp = 255; |
| 66 } | 61 } |
| 67 frame[yIdx] = static_cast<uint8_t>(yTmp); | 62 frame[yIdx] = static_cast<uint8_t>(yTmp); |
| 68 } | 63 } |
| 69 | 64 |
| 70 VideoProcessingModule::FrameStats stats; | 65 VideoProcessing::FrameStats stats; |
| 71 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); | 66 vp_->GetFrameStats(video_frame_, &stats); |
| 72 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, | 67 EXPECT_GT(stats.num_pixels, 0u); |
| 68 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, |
| 73 stats), 0); | 69 stats), 0); |
| 74 EXPECT_NE(VideoProcessingModule::kDarkWarning, brightnessWarning); | 70 EXPECT_NE(VideoProcessing::kDarkWarning, brightnessWarning); |
| 75 if (brightnessWarning == VideoProcessingModule::kBrightWarning) | 71 if (brightnessWarning == VideoProcessing::kBrightWarning) { |
| 76 { | |
| 77 warningCount++; | 72 warningCount++; |
| 78 } | 73 } |
| 79 } | 74 } |
| 80 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 75 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
| 81 | 76 |
| 82 // Expect many brightness warnings | 77 // Expect many brightness warnings |
| 83 warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 78 warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
| 84 printf("Bright foreman: %.1f %%\n", warningProportion); | 79 printf("Bright foreman: %.1f %%\n", warningProportion); |
| 85 EXPECT_GT(warningProportion, 95); | 80 EXPECT_GT(warningProportion, 95); |
| 86 | 81 |
| 87 rewind(source_file_); | 82 rewind(source_file_); |
| 88 frameNum = 0; | 83 frameNum = 0; |
| 89 warningCount = 0; | 84 warningCount = 0; |
| 90 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 85 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
| 91 frame_length_ && frameNum < 300) | 86 frame_length_ && frameNum < 300) { |
| 92 { | |
| 93 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 87 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, |
| 94 height_, 0, kVideoRotation_0, &video_frame_)); | 88 height_, 0, kVideoRotation_0, &video_frame_)); |
| 95 frameNum++; | 89 frameNum++; |
| 96 | 90 |
| 97 uint8_t* y_plane = video_frame_.buffer(kYPlane); | 91 uint8_t* y_plane = video_frame_.buffer(kYPlane); |
| 98 int32_t yTmp = 0; | 92 int32_t yTmp = 0; |
| 99 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) | 93 for (int yIdx = 0; yIdx < width_ * height_; yIdx++) { |
| 100 { | |
| 101 yTmp = y_plane[yIdx] >> 1; | 94 yTmp = y_plane[yIdx] >> 1; |
| 102 y_plane[yIdx] = static_cast<uint8_t>(yTmp); | 95 y_plane[yIdx] = static_cast<uint8_t>(yTmp); |
| 103 } | 96 } |
| 104 | 97 |
| 105 VideoProcessingModule::FrameStats stats; | 98 VideoProcessing::FrameStats stats; |
| 106 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); | 99 vp_->GetFrameStats(video_frame_, &stats); |
| 107 ASSERT_GE(brightnessWarning = vpm_->BrightnessDetection(video_frame_, | 100 EXPECT_GT(stats.num_pixels, 0u); |
| 101 ASSERT_GE(brightnessWarning = vp_->BrightnessDetection(video_frame_, |
| 108 stats), 0); | 102 stats), 0); |
| 109 EXPECT_NE(VideoProcessingModule::kBrightWarning, brightnessWarning); | 103 EXPECT_NE(VideoProcessing::kBrightWarning, brightnessWarning); |
| 110 if (brightnessWarning == VideoProcessingModule::kDarkWarning) | 104 if (brightnessWarning == VideoProcessing::kDarkWarning) { |
| 111 { | |
| 112 warningCount++; | 105 warningCount++; |
| 113 } | 106 } |
| 114 } | 107 } |
| 115 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 108 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
| 116 | 109 |
| 117 // Expect many darkness warnings | 110 // Expect many darkness warnings |
| 118 warningProportion = static_cast<float>(warningCount) / frameNum * 100; | 111 warningProportion = static_cast<float>(warningCount) / frameNum * 100; |
| 119 printf("Dark foreman: %.1f %%\n\n", warningProportion); | 112 printf("Dark foreman: %.1f %%\n\n", warningProportion); |
| 120 EXPECT_GT(warningProportion, 90); | 113 EXPECT_GT(warningProportion, 90); |
| 121 } | 114 } |
| 115 } // namespace webrtc |
| OLD | NEW |