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

Side by Side Diff: webrtc/modules/desktop_capture/blank_detector_desktop_capturer_wrapper_unittest.cc

Issue 2709523003: BlankDetectorDesktopCapturerWrapper to detect a blank DesktopFrame (Closed)
Patch Set: Resolve review comments Created 3 years, 9 months 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
(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 Initialize(int permanent_failure_threshold);
33 void PerfTest(DesktopCapturer* capturer);
34
35 const int frame_width_ = 1024;
36 const int frame_height_ = 768;
37 int permanent_failure_threshold_ = 0;
38 std::unique_ptr<BlankDetectorDesktopCapturerWrapper> wrapper_;
39 DesktopCapturer* capturer_ = nullptr;
40 BlackWhiteDesktopFramePainter painter_;
41 int num_frames_captured_ = 0;
42 DesktopCapturer::Result last_result_ = DesktopCapturer::Result::SUCCESS;
43 std::unique_ptr<DesktopFrame> last_frame_;
44
45 private:
46 // DesktopCapturer::Callback interface.
47 void OnCaptureResult(DesktopCapturer::Result result,
48 std::unique_ptr<DesktopFrame> frame) override;
49
50 PainterDesktopFrameGenerator frame_generator_;
51 };
52
53 BlankDetectorDesktopCapturerWrapperTest::
54 BlankDetectorDesktopCapturerWrapperTest() {
55 Initialize(100);
56 }
57
58 BlankDetectorDesktopCapturerWrapperTest::
59 ~BlankDetectorDesktopCapturerWrapperTest() = default;
60
61 void BlankDetectorDesktopCapturerWrapperTest::Initialize(
62 int permanent_failure_threshold) {
63 permanent_failure_threshold_ = permanent_failure_threshold;
64 frame_generator_.size()->set(frame_width_, frame_height_);
65 frame_generator_.set_desktop_frame_painter(&painter_);
66 std::unique_ptr<DesktopCapturer> capturer(new FakeDesktopCapturer());
67 FakeDesktopCapturer* fake_capturer =
68 static_cast<FakeDesktopCapturer*>(capturer.get());
69 fake_capturer->set_frame_generator(&frame_generator_);
70 capturer_ = fake_capturer;
71 wrapper_.reset(new BlankDetectorDesktopCapturerWrapper(
72 std::move(capturer), RgbaColor(0, 0, 0, 0),
73 permanent_failure_threshold));
74 wrapper_->Start(this);
75 }
76
77 void BlankDetectorDesktopCapturerWrapperTest::OnCaptureResult(
78 DesktopCapturer::Result result,
79 std::unique_ptr<DesktopFrame> frame) {
80 last_result_ = result;
81 last_frame_ = std::move(frame);
82 num_frames_captured_++;
83 }
84
85 void BlankDetectorDesktopCapturerWrapperTest::PerfTest(
86 DesktopCapturer* capturer) {
87 for (int i = 0; i < 10000; i++) {
88 capturer->CaptureFrame();
89 ASSERT_EQ(num_frames_captured_, i + 1);
90 }
91 }
92
93 TEST_F(BlankDetectorDesktopCapturerWrapperTest, ShouldDetectBlankFrame) {
94 wrapper_->CaptureFrame();
95 ASSERT_EQ(num_frames_captured_, 1);
96 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_TEMPORARY);
97 ASSERT_FALSE(last_frame_);
98 }
99
100 TEST_F(BlankDetectorDesktopCapturerWrapperTest, ShouldPassBlankDetection) {
101 painter_.updated_region()->AddRect(DesktopRect::MakeXYWH(0, 0, 100, 100));
102 wrapper_->CaptureFrame();
103 ASSERT_EQ(num_frames_captured_, 1);
104 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
105 ASSERT_TRUE(last_frame_);
106
107 painter_.updated_region()->AddRect(
108 DesktopRect::MakeXYWH(frame_width_ - 100, frame_height_ - 100, 100, 100));
109 wrapper_->CaptureFrame();
110 ASSERT_EQ(num_frames_captured_, 2);
111 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
112 ASSERT_TRUE(last_frame_);
113
114 painter_.updated_region()->AddRect(
115 DesktopRect::MakeXYWH(0, frame_height_ - 100, 100, 100));
116 wrapper_->CaptureFrame();
117 ASSERT_EQ(num_frames_captured_, 3);
118 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
119 ASSERT_TRUE(last_frame_);
120
121 painter_.updated_region()->AddRect(
122 DesktopRect::MakeXYWH(frame_width_ - 100, 0, 100, 100));
123 wrapper_->CaptureFrame();
124 ASSERT_EQ(num_frames_captured_, 4);
125 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
126 ASSERT_TRUE(last_frame_);
127
128 painter_.updated_region()->AddRect(DesktopRect::MakeXYWH(
129 (frame_width_ >> 1) - 50, (frame_height_ >> 1) - 50, 100, 100));
130 wrapper_->CaptureFrame();
131 ASSERT_EQ(num_frames_captured_, 5);
132 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
133 ASSERT_TRUE(last_frame_);
134 }
135
136 TEST_F(BlankDetectorDesktopCapturerWrapperTest, ShouldReturnPermanentError) {
137 for (int i = 0; i < permanent_failure_threshold_ - 1; i++) {
138 wrapper_->CaptureFrame();
139 ASSERT_EQ(num_frames_captured_, i + 1);
140 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_TEMPORARY);
141 ASSERT_FALSE(last_frame_);
142 }
143 wrapper_->CaptureFrame();
144 ASSERT_EQ(num_frames_captured_, permanent_failure_threshold_);
145 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_PERMANENT);
146 ASSERT_FALSE(last_frame_);
147 }
148
149 TEST_F(BlankDetectorDesktopCapturerWrapperTest,
150 ShouldNotCheckAfterANonBlankFrameReceived) {
151 wrapper_->CaptureFrame();
152 ASSERT_EQ(num_frames_captured_, 1);
153 ASSERT_EQ(last_result_, DesktopCapturer::Result::ERROR_TEMPORARY);
154 ASSERT_FALSE(last_frame_);
155
156 painter_.updated_region()->AddRect(
157 DesktopRect::MakeXYWH(frame_width_ - 100, 0, 100, 100));
158 wrapper_->CaptureFrame();
159 ASSERT_EQ(num_frames_captured_, 2);
160 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
161 ASSERT_TRUE(last_frame_);
162
163 for (int i = 0; i < permanent_failure_threshold_; i++) {
164 wrapper_->CaptureFrame();
165 ASSERT_EQ(num_frames_captured_, i + 3);
166 ASSERT_EQ(last_result_, DesktopCapturer::Result::SUCCESS);
167 ASSERT_TRUE(last_frame_);
168 }
169 }
170
171 // There is no perceptible impact by using BlankDetectorDesktopCapturerWrapper.
172 // i.e. less than 0.2ms per frame.
173 // [ OK ] DISABLED_Performance (11040 ms)
174 // [ OK ] DISABLED_PerformanceComparison (9488 ms)
175 TEST_F(BlankDetectorDesktopCapturerWrapperTest, DISABLED_Performance) {
176 Initialize(-1);
177 PerfTest(wrapper_.get());
178 }
179
180 TEST_F(BlankDetectorDesktopCapturerWrapperTest,
181 DISABLED_PerformanceComparison) {
182 capturer_->Start(this);
183 PerfTest(capturer_);
184 }
185
186 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698