OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/desktop_capture/blank_detector_desktop_capturer_wrapper
.h" |
| 12 |
| 13 #include <memory> |
| 14 #include <utility> |
| 15 |
| 16 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
| 17 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 18 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" |
| 19 #include "webrtc/modules/desktop_capture/fake_desktop_capturer.h" |
| 20 #include "webrtc/test/gtest.h" |
| 21 |
| 22 namespace webrtc { |
| 23 |
| 24 class BlankDetectorDesktopCapturerWrapperTest |
| 25 : public testing::Test, |
| 26 public DesktopCapturer::Callback { |
| 27 public: |
| 28 BlankDetectorDesktopCapturerWrapperTest(); |
| 29 ~BlankDetectorDesktopCapturerWrapperTest() override; |
| 30 |
| 31 protected: |
| 32 void PerfTest(DesktopCapturer* capturer); |
| 33 |
| 34 const int frame_width_ = 1024; |
| 35 const int frame_height_ = 768; |
| 36 std::unique_ptr<BlankDetectorDesktopCapturerWrapper> wrapper_; |
| 37 DesktopCapturer* capturer_ = nullptr; |
| 38 BlackWhiteDesktopFramePainter painter_; |
| 39 int num_frames_captured_ = 0; |
| 40 DesktopCapturer::Result last_result_ = DesktopCapturer::Result::SUCCESS; |
| 41 std::unique_ptr<DesktopFrame> last_frame_; |
| 42 |
| 43 private: |
| 44 // DesktopCapturer::Callback interface. |
| 45 void OnCaptureResult(DesktopCapturer::Result result, |
| 46 std::unique_ptr<DesktopFrame> frame) override; |
| 47 |
| 48 PainterDesktopFrameGenerator frame_generator_; |
| 49 }; |
| 50 |
| 51 BlankDetectorDesktopCapturerWrapperTest:: |
| 52 BlankDetectorDesktopCapturerWrapperTest() { |
| 53 frame_generator_.size()->set(frame_width_, frame_height_); |
| 54 frame_generator_.set_desktop_frame_painter(&painter_); |
| 55 std::unique_ptr<DesktopCapturer> capturer(new FakeDesktopCapturer()); |
| 56 FakeDesktopCapturer* fake_capturer = |
| 57 static_cast<FakeDesktopCapturer*>(capturer.get()); |
| 58 fake_capturer->set_frame_generator(&frame_generator_); |
| 59 capturer_ = fake_capturer; |
| 60 wrapper_.reset(new BlankDetectorDesktopCapturerWrapper( |
| 61 std::move(capturer), RgbaColor(0, 0, 0, 0))); |
| 62 wrapper_->Start(this); |
| 63 } |
| 64 |
| 65 BlankDetectorDesktopCapturerWrapperTest:: |
| 66 ~BlankDetectorDesktopCapturerWrapperTest() = default; |
| 67 |
| 68 void BlankDetectorDesktopCapturerWrapperTest::OnCaptureResult( |
| 69 DesktopCapturer::Result result, |
| 70 std::unique_ptr<DesktopFrame> frame) { |
| 71 last_result_ = result; |
| 72 last_frame_ = std::move(frame); |
| 73 num_frames_captured_++; |
| 74 } |
| 75 |
| 76 void BlankDetectorDesktopCapturerWrapperTest::PerfTest( |
| 77 DesktopCapturer* capturer) { |
| 78 for (int i = 0; i < 10000; i++) { |
| 79 capturer->CaptureFrame(); |
| 80 ASSERT_EQ(num_frames_captured_, i + 1); |
| 81 } |
| 82 } |
| 83 |
| 84 TEST_F(BlankDetectorDesktopCapturerWrapperTest, ShouldDetectBlankFrame) { |
| 85 wrapper_->CaptureFrame(); |
| 86 ASSERT_EQ(num_frames_captured_, 1); |
| 87 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_TEMPORARY); |
| 88 ASSERT_FALSE(last_frame_); |
| 89 } |
| 90 |
| 91 TEST_F(BlankDetectorDesktopCapturerWrapperTest, ShouldPassBlankDetection) { |
| 92 painter_.updated_region()->AddRect(DesktopRect::MakeXYWH(0, 0, 100, 100)); |
| 93 wrapper_->CaptureFrame(); |
| 94 ASSERT_EQ(num_frames_captured_, 1); |
| 95 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 96 ASSERT_TRUE(last_frame_); |
| 97 |
| 98 painter_.updated_region()->AddRect( |
| 99 DesktopRect::MakeXYWH(frame_width_ - 100, frame_height_ - 100, 100, 100)); |
| 100 wrapper_->CaptureFrame(); |
| 101 ASSERT_EQ(num_frames_captured_, 2); |
| 102 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 103 ASSERT_TRUE(last_frame_); |
| 104 |
| 105 painter_.updated_region()->AddRect( |
| 106 DesktopRect::MakeXYWH(0, frame_height_ - 100, 100, 100)); |
| 107 wrapper_->CaptureFrame(); |
| 108 ASSERT_EQ(num_frames_captured_, 3); |
| 109 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 110 ASSERT_TRUE(last_frame_); |
| 111 |
| 112 painter_.updated_region()->AddRect( |
| 113 DesktopRect::MakeXYWH(frame_width_ - 100, 0, 100, 100)); |
| 114 wrapper_->CaptureFrame(); |
| 115 ASSERT_EQ(num_frames_captured_, 4); |
| 116 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 117 ASSERT_TRUE(last_frame_); |
| 118 |
| 119 painter_.updated_region()->AddRect(DesktopRect::MakeXYWH( |
| 120 (frame_width_ >> 1) - 50, (frame_height_ >> 1) - 50, 100, 100)); |
| 121 wrapper_->CaptureFrame(); |
| 122 ASSERT_EQ(num_frames_captured_, 5); |
| 123 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 124 ASSERT_TRUE(last_frame_); |
| 125 } |
| 126 |
| 127 TEST_F(BlankDetectorDesktopCapturerWrapperTest, |
| 128 ShouldNotCheckAfterANonBlankFrameReceived) { |
| 129 wrapper_->CaptureFrame(); |
| 130 ASSERT_EQ(num_frames_captured_, 1); |
| 131 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_TEMPORARY); |
| 132 ASSERT_FALSE(last_frame_); |
| 133 |
| 134 painter_.updated_region()->AddRect( |
| 135 DesktopRect::MakeXYWH(frame_width_ - 100, 0, 100, 100)); |
| 136 wrapper_->CaptureFrame(); |
| 137 ASSERT_EQ(num_frames_captured_, 2); |
| 138 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 139 ASSERT_TRUE(last_frame_); |
| 140 |
| 141 for (int i = 0; i < 100; i++) { |
| 142 wrapper_->CaptureFrame(); |
| 143 ASSERT_EQ(num_frames_captured_, i + 3); |
| 144 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS); |
| 145 ASSERT_TRUE(last_frame_); |
| 146 } |
| 147 } |
| 148 |
| 149 // There is no perceptible impact by using BlankDetectorDesktopCapturerWrapper. |
| 150 // i.e. less than 0.2ms per frame. |
| 151 // [ OK ] DISABLED_Performance (10210 ms) |
| 152 // [ OK ] DISABLED_PerformanceComparison (8791 ms) |
| 153 TEST_F(BlankDetectorDesktopCapturerWrapperTest, DISABLED_Performance) { |
| 154 PerfTest(wrapper_.get()); |
| 155 } |
| 156 |
| 157 TEST_F(BlankDetectorDesktopCapturerWrapperTest, |
| 158 DISABLED_PerformanceComparison) { |
| 159 capturer_->Start(this); |
| 160 PerfTest(capturer_); |
| 161 } |
| 162 |
| 163 } // namespace webrtc |
OLD | NEW |