OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <initializer_list> | 14 #include <initializer_list> |
15 #include <iostream> // TODO(zijiehe): Remove once flaky has been resolved. | |
15 #include <memory> | 16 #include <memory> |
16 #include <utility> | 17 #include <utility> |
17 | 18 |
19 // TODO(zijiehe): Remove once flaky has been resolved. | |
20 #include "webrtc/base/base64.h" | |
18 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/constructormagic.h" | 22 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/logging.h" | 23 #include "webrtc/base/logging.h" |
21 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | 24 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
22 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 25 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
23 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 26 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
24 #include "webrtc/modules/desktop_capture/desktop_region.h" | 27 #include "webrtc/modules/desktop_capture/desktop_region.h" |
25 #include "webrtc/modules/desktop_capture/mock_desktop_capturer_callback.h" | 28 #include "webrtc/modules/desktop_capture/mock_desktop_capturer_callback.h" |
26 #include "webrtc/modules/desktop_capture/rgba_color.h" | 29 #include "webrtc/modules/desktop_capture/rgba_color.h" |
27 #include "webrtc/modules/desktop_capture/screen_drawer.h" | 30 #include "webrtc/modules/desktop_capture/screen_drawer.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we | 112 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we |
110 // won't draw a black or white rectangle. | 113 // won't draw a black or white rectangle. |
111 for (int c = 0; c < 3; c++) { | 114 for (int c = 0; c < 3; c++) { |
112 // A fixed size rectangle. | 115 // A fixed size rectangle. |
113 for (int i = 0; i < kTestArea - kRectSize; i += 16) { | 116 for (int i = 0; i < kTestArea - kRectSize; i += 16) { |
114 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); | 117 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); |
115 rect.Translate(drawer->DrawableRegion().top_left()); | 118 rect.Translate(drawer->DrawableRegion().top_left()); |
116 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), | 119 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), |
117 (c == 1 ? (i & 0xff) : 0x7f), | 120 (c == 1 ? (i & 0xff) : 0x7f), |
118 (c == 2 ? (i & 0xff) : 0x7f)); | 121 (c == 2 ? (i & 0xff) : 0x7f)); |
119 TestCaptureOneFrame(capturers, drawer.get(), rect, color); | 122 if (!TestCaptureOneFrame(capturers, drawer.get(), rect, color)) { |
123 // Fail fast. | |
124 return; | |
Sergey Ulanov
2016/11/18 01:21:42
Not sure why we need to return result here? The ca
Hzj_jie
2016/11/18 04:32:00
Ah, it's simply because I do not know this functio
| |
125 } | |
120 } | 126 } |
121 | 127 |
122 // A variable-size rectangle. | 128 // A variable-size rectangle. |
123 for (int i = 0; i < kTestArea - kRectSize; i += 16) { | 129 for (int i = 0; i < kTestArea - kRectSize; i += 16) { |
124 DesktopRect rect = DesktopRect::MakeXYWH(kRectSize, kRectSize, i, i); | 130 DesktopRect rect = DesktopRect::MakeXYWH(kRectSize, kRectSize, i, i); |
125 rect.Translate(drawer->DrawableRegion().top_left()); | 131 rect.Translate(drawer->DrawableRegion().top_left()); |
126 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), | 132 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), |
127 (c == 1 ? (i & 0xff) : 0x7f), | 133 (c == 1 ? (i & 0xff) : 0x7f), |
128 (c == 2 ? (i & 0xff) : 0x7f)); | 134 (c == 2 ? (i & 0xff) : 0x7f)); |
129 TestCaptureOneFrame(capturers, drawer.get(), rect, color); | 135 if (!TestCaptureOneFrame(capturers, drawer.get(), rect, color)) { |
136 // Fail fast. | |
137 return; | |
138 } | |
130 } | 139 } |
131 } | 140 } |
132 } | 141 } |
133 | 142 |
134 void TestCaptureUpdatedRegion() { | 143 void TestCaptureUpdatedRegion() { |
135 TestCaptureUpdatedRegion({capturer_.get()}); | 144 TestCaptureUpdatedRegion({capturer_.get()}); |
136 } | 145 } |
137 | 146 |
138 #if defined(WEBRTC_WIN) | 147 #if defined(WEBRTC_WIN) |
139 // Enable allow_directx_capturer in DesktopCaptureOptions, but let | 148 // Enable allow_directx_capturer in DesktopCaptureOptions, but let |
(...skipping 23 matching lines...) Expand all Loading... | |
163 #endif // defined(WEBRTC_WIN) | 172 #endif // defined(WEBRTC_WIN) |
164 | 173 |
165 std::unique_ptr<DesktopCapturer> capturer_; | 174 std::unique_ptr<DesktopCapturer> capturer_; |
166 MockDesktopCapturerCallback callback_; | 175 MockDesktopCapturerCallback callback_; |
167 | 176 |
168 private: | 177 private: |
169 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, | 178 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, |
170 // typically 30 seconds, until they succeeded captured a |color| rectangle at | 179 // typically 30 seconds, until they succeeded captured a |color| rectangle at |
171 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two | 180 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two |
172 // attempts to wait for the screen to update. | 181 // attempts to wait for the screen to update. |
173 void TestCaptureOneFrame(std::vector<DesktopCapturer*> capturers, | 182 // |
183 // Returns false to indicate the error. | |
184 // TODO(zijiehe): Remove return value of this function once flaky of | |
185 // ScreenCapturerIntegrationTest has been resolved. | |
186 bool TestCaptureOneFrame(std::vector<DesktopCapturer*> capturers, | |
174 ScreenDrawer* drawer, | 187 ScreenDrawer* drawer, |
175 DesktopRect rect, | 188 DesktopRect rect, |
176 RgbaColor color) { | 189 RgbaColor color) { |
177 const int wait_capture_round = 600; | 190 const int wait_capture_round = 600; |
178 drawer->Clear(); | 191 drawer->Clear(); |
179 size_t succeeded_capturers = 0; | 192 size_t succeeded_capturers = 0; |
180 for (int i = 0; i < wait_capture_round; i++) { | 193 for (int i = 0; i < wait_capture_round; i++) { |
181 drawer->DrawRectangle(rect, color); | 194 drawer->DrawRectangle(rect, color); |
182 drawer->WaitForPendingDraws(); | 195 drawer->WaitForPendingDraws(); |
183 for (size_t j = 0; j < capturers.size(); j++) { | 196 for (size_t j = 0; j < capturers.size(); j++) { |
184 if (capturers[j] == nullptr) { | 197 if (capturers[j] == nullptr) { |
185 // DesktopCapturer should return an empty updated_region() if no | 198 // DesktopCapturer should return an empty updated_region() if no |
186 // update detected. So we won't test it again if it has captured | 199 // update detected. So we won't test it again if it has captured the |
187 // the rectangle we drew. | 200 // rectangle we drew. |
188 continue; | 201 continue; |
189 } | 202 } |
190 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); | 203 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); |
191 if (!frame) { | 204 if (!frame) { |
192 // CaptureFrame() has triggered an assertion failure already, we | 205 // CaptureFrame() has triggered an assertion failure already, we only |
193 // only need to return here. | 206 // need to return here. |
194 return; | 207 return false; |
195 } | 208 } |
196 | 209 |
197 if (ArePixelsColoredBy( | 210 if (ArePixelsColoredBy( |
198 *frame, rect, color, drawer->MayDrawIncompleteShapes())) { | 211 *frame, rect, color, drawer->MayDrawIncompleteShapes())) { |
199 capturers[j] = nullptr; | 212 capturers[j] = nullptr; |
200 succeeded_capturers++; | 213 succeeded_capturers++; |
201 } | 214 } |
215 // The following else if statement is for debugging purpose only, which | |
216 // should be removed after flaky of ScreenCapturerIntegrationTest has | |
217 // been resolved. | |
218 else if (i == wait_capture_round - 1) { | |
219 std::string result; | |
220 rtc::Base64::EncodeFromArray(frame->data(), | |
221 frame->size().height() * frame->stride(), | |
222 &result); | |
223 // LOG and ASSERT won't output a long string, so we can only use | |
Sergey Ulanov
2016/11/18 01:21:42
What do you mean by "long string"? It looks like |
Hzj_jie
2016/11/18 04:32:00
Done.
| |
224 // std::out here. | |
225 std::cout << frame->size().width() << " x " << frame->size().height() | |
226 << std::endl; | |
227 // Split the entire string (can be over 4M) into several lines to | |
228 // avoid browser from stucking. | |
229 static const size_t kLineLength = 32768; | |
230 const char* result_end = result.c_str() + result.length(); | |
231 for (const char* it = result.c_str(); | |
232 it < result_end; | |
233 it += kLineLength) { | |
234 const size_t max_length = result_end - it; | |
235 std::cout << std::string(it, std::min(kLineLength, max_length)) | |
236 << std::endl; | |
237 } | |
238 EXPECT_TRUE(false) << "ScreenCapturerIntegrationTest is flaky. " | |
239 "Please disable *all* tests in " | |
240 "screen_capturer_integration_test.cc"; | |
241 } | |
202 } | 242 } |
203 | 243 |
204 if (succeeded_capturers == capturers.size()) { | 244 if (succeeded_capturers == capturers.size()) { |
205 break; | 245 break; |
206 } | 246 } |
207 } | 247 } |
208 | 248 |
209 ASSERT_EQ(succeeded_capturers, capturers.size()); | 249 EXPECT_EQ(succeeded_capturers, capturers.size()); |
250 return succeeded_capturers == capturers.size(); | |
210 } | 251 } |
211 | 252 |
212 // Expects |capturer| to successfully capture a frame, and returns it. | 253 // Expects |capturer| to successfully capture a frame, and returns it. |
213 std::unique_ptr<DesktopFrame> CaptureFrame(DesktopCapturer* capturer) { | 254 std::unique_ptr<DesktopFrame> CaptureFrame(DesktopCapturer* capturer) { |
214 std::unique_ptr<DesktopFrame> frame; | 255 std::unique_ptr<DesktopFrame> frame; |
215 EXPECT_CALL(callback_, | 256 EXPECT_CALL(callback_, |
216 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) | 257 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, _)) |
217 .WillOnce(SaveUniquePtrArg(&frame)); | 258 .WillOnce(SaveUniquePtrArg(&frame)); |
218 capturer->CaptureFrame(); | 259 capturer->CaptureFrame(); |
219 EXPECT_TRUE(frame); | 260 EXPECT_TRUE(frame); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) { | 324 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) { |
284 // Even DirectX capturer is not supported in current system, we should be able | 325 // Even DirectX capturer is not supported in current system, we should be able |
285 // to select a usable capturer. | 326 // to select a usable capturer. |
286 MaybeCreateDirectxCapturer(); | 327 MaybeCreateDirectxCapturer(); |
287 TestCaptureUpdatedRegion(); | 328 TestCaptureUpdatedRegion(); |
288 } | 329 } |
289 | 330 |
290 #endif // defined(WEBRTC_WIN) | 331 #endif // defined(WEBRTC_WIN) |
291 | 332 |
292 } // namespace webrtc | 333 } // namespace webrtc |
OLD | NEW |