| 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 "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" | 11 #include "webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.h" |
| 12 | 12 |
| 13 #include <initializer_list> | 13 #include <initializer_list> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/base/random.h" | 18 #include "webrtc/base/random.h" |
| 19 #include "webrtc/base/timeutils.h" | 19 #include "webrtc/base/timeutils.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 21 #include "webrtc/modules/desktop_capture/desktop_region.h" | 21 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 22 #include "webrtc/modules/desktop_capture/differ_block.h" | 22 #include "webrtc/modules/desktop_capture/differ_block.h" |
| 23 #include "webrtc/modules/desktop_capture/fake_screen_capturer.h" | 23 #include "webrtc/modules/desktop_capture/fake_screen_capturer.h" |
| 24 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" | 24 #include "webrtc/modules/desktop_capture/mock_desktop_capturer_callback.h" |
| 25 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 25 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
| 26 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
| 27 #include "webrtc/typedefs.h" | 27 #include "webrtc/typedefs.h" |
| 28 | 28 |
| 29 namespace webrtc { | 29 namespace webrtc { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Compares and asserts |frame|.updated_region() equals to |rects|. This | 33 // Compares and asserts |frame|.updated_region() equals to |rects|. This |
| 34 // function does not care about the order of the |rects| and it does not expect | 34 // function does not care about the order of the |rects| and it does not expect |
| (...skipping 28 matching lines...) Expand all Loading... |
| 63 intersect.IntersectWith(frame.updated_region()); | 63 intersect.IntersectWith(frame.updated_region()); |
| 64 ASSERT_TRUE(region.Equals(intersect)); | 64 ASSERT_TRUE(region.Equals(intersect)); |
| 65 | 65 |
| 66 // Difference between |rects| and |frame|.updated_region() should not cover | 66 // Difference between |rects| and |frame|.updated_region() should not cover |
| 67 // areas which have larger than twice of kBlockSize width and height. | 67 // areas which have larger than twice of kBlockSize width and height. |
| 68 // | 68 // |
| 69 // Explanation of the 'twice' of kBlockSize (indeed kBlockSize * 2 - 2) is | 69 // Explanation of the 'twice' of kBlockSize (indeed kBlockSize * 2 - 2) is |
| 70 // following, | 70 // following, |
| 71 // (Each block in the following grid is a 8 x 8 pixels area. X means the real | 71 // (Each block in the following grid is a 8 x 8 pixels area. X means the real |
| 72 // updated area, m means the updated area marked by | 72 // updated area, m means the updated area marked by |
| 73 // ScreenCapturerDifferWrapper.) | 73 // DesktopCapturerDifferWrapper.) |
| 74 // +---+---+---+---+---+---+---+---+ | 74 // +---+---+---+---+---+---+---+---+ |
| 75 // | X | m | m | m | m | m | m | m | | 75 // | X | m | m | m | m | m | m | m | |
| 76 // +---+---+---+---+---+---+---+---+ | 76 // +---+---+---+---+---+---+---+---+ |
| 77 // | m | m | m | m | m | m | m | m | | 77 // | m | m | m | m | m | m | m | m | |
| 78 // +---+---+---+---+---+---+---+---+ | 78 // +---+---+---+---+---+---+---+---+ |
| 79 // | m | m | m | m | m | m | m | m | | 79 // | m | m | m | m | m | m | m | m | |
| 80 // +---+---+---+---+---+---+---+---+ | 80 // +---+---+---+---+---+---+---+---+ |
| 81 // | m | m | m | m | m | m | m | X | | 81 // | m | m | m | m | m | m | m | X | |
| 82 // +---+---+---+---+---+---+---+---+ | 82 // +---+---+---+---+---+---+---+---+ |
| 83 // The top left [0, 0] - [8, 8] and right bottom [56, 24] - [64, 32] blocks of | 83 // The top left [0, 0] - [8, 8] and right bottom [56, 24] - [64, 32] blocks of |
| 84 // this area are updated. But since ScreenCapturerDifferWrapper compares | 84 // this area are updated. But since DesktopCapturerDifferWrapper compares |
| 85 // 32 x 32 blocks by default, this entire area is marked as updated. So the | 85 // 32 x 32 blocks by default, this entire area is marked as updated. So the |
| 86 // [8, 8] - [56, 32] is expected to be covered in the difference. | 86 // [8, 8] - [56, 32] is expected to be covered in the difference. |
| 87 // | 87 // |
| 88 // But if [0, 0] - [8, 8] and [64, 24] - [72, 32] blocks are updated, | 88 // But if [0, 0] - [8, 8] and [64, 24] - [72, 32] blocks are updated, |
| 89 // +---+---+---+---+---+---+---+---+---+---+---+---+ | 89 // +---+---+---+---+---+---+---+---+---+---+---+---+ |
| 90 // | X | m | m | m | | | | | m | m | m | m | | 90 // | X | m | m | m | | | | | m | m | m | m | |
| 91 // +---+---+---+---+---+---+---+---+---+---+---+---+ | 91 // +---+---+---+---+---+---+---+---+---+---+---+---+ |
| 92 // | m | m | m | m | | | | | m | m | m | m | | 92 // | m | m | m | m | | | | | m | m | m | m | |
| 93 // +---+---+---+---+---+---+---+---+---+---+---+---+ | 93 // +---+---+---+---+---+---+---+---+---+---+---+---+ |
| 94 // | m | m | m | m | | | | | m | m | m | m | | 94 // | m | m | m | m | | | | | m | m | m | m | |
| 95 // +---+---+---+---+---+---+---+---+---+---+---+---+ | 95 // +---+---+---+---+---+---+---+---+---+---+---+---+ |
| 96 // | m | m | m | m | | | | | X | m | m | m | | 96 // | m | m | m | m | | | | | X | m | m | m | |
| 97 // +---+---+---+---+---+---+---+---+---+---+---+---+ | 97 // +---+---+---+---+---+---+---+---+---+---+---+---+ |
| 98 // the [8, 8] - [64, 32] is not expected to be covered in the difference. As | 98 // the [8, 8] - [64, 32] is not expected to be covered in the difference. As |
| 99 // ScreenCapturerDifferWrapper should only mark [0, 0] - [32, 32] and | 99 // DesktopCapturerDifferWrapper should only mark [0, 0] - [32, 32] and |
| 100 // [64, 0] - [96, 32] as updated. | 100 // [64, 0] - [96, 32] as updated. |
| 101 DesktopRegion differ(frame.updated_region()); | 101 DesktopRegion differ(frame.updated_region()); |
| 102 differ.Subtract(region); | 102 differ.Subtract(region); |
| 103 for (DesktopRegion::Iterator it(differ); !it.IsAtEnd(); it.Advance()) { | 103 for (DesktopRegion::Iterator it(differ); !it.IsAtEnd(); it.Advance()) { |
| 104 ASSERT_TRUE(it.rect().width() <= kBlockSize * 2 - 2 || | 104 ASSERT_TRUE(it.rect().width() <= kBlockSize * 2 - 2 || |
| 105 it.rect().height() <= kBlockSize * 2 - 2); | 105 it.rect().height() <= kBlockSize * 2 - 2); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Executes a ScreenCapturerDifferWrapper::Capture() and compares its output | 109 // Executes a DesktopCapturerDifferWrapper::Capture() and compares its output |
| 110 // DesktopFrame::updated_region() with |updated_region| if |check_result| is | 110 // DesktopFrame::updated_region() with |updated_region| if |check_result| is |
| 111 // true. If |exactly_match| is true, AssertUpdatedRegionIs() will be used, | 111 // true. If |exactly_match| is true, AssertUpdatedRegionIs() will be used, |
| 112 // otherwise AssertUpdatedRegionCovers() will be used. | 112 // otherwise AssertUpdatedRegionCovers() will be used. |
| 113 template <template <typename, typename...> class T = std::initializer_list, | 113 template <template <typename, typename...> class T = std::initializer_list, |
| 114 typename... Rect> | 114 typename... Rect> |
| 115 void ExecuteDifferWrapperCase(BlackWhiteDesktopFramePainter* frame_painter, | 115 void ExecuteDifferWrapperCase(BlackWhiteDesktopFramePainter* frame_painter, |
| 116 ScreenCapturerDifferWrapper* capturer, | 116 DesktopCapturerDifferWrapper* capturer, |
| 117 MockScreenCapturerCallback* callback, | 117 MockDesktopCapturerCallback* callback, |
| 118 const T<DesktopRect, Rect...>& updated_region, | 118 const T<DesktopRect, Rect...>& updated_region, |
| 119 bool check_result, | 119 bool check_result, |
| 120 bool exactly_match) { | 120 bool exactly_match) { |
| 121 EXPECT_CALL(*callback, | 121 EXPECT_CALL(*callback, |
| 122 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) | 122 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) |
| 123 .Times(1) | 123 .Times(1) |
| 124 .WillOnce(testing::Invoke([&updated_region, check_result, exactly_match]( | 124 .WillOnce(testing::Invoke([&updated_region, check_result, exactly_match]( |
| 125 DesktopCapturer::Result result, | 125 DesktopCapturer::Result result, |
| 126 std::unique_ptr<DesktopFrame>* frame) { | 126 std::unique_ptr<DesktopFrame>* frame) { |
| 127 ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS); | 127 ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS); |
| 128 if (check_result) { | 128 if (check_result) { |
| 129 if (exactly_match) { | 129 if (exactly_match) { |
| 130 AssertUpdatedRegionIs(**frame, updated_region); | 130 AssertUpdatedRegionIs(**frame, updated_region); |
| 131 } else { | 131 } else { |
| 132 AssertUpdatedRegionCovers(**frame, updated_region); | 132 AssertUpdatedRegionCovers(**frame, updated_region); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 })); | 135 })); |
| 136 for (const auto& rect : updated_region) { | 136 for (const auto& rect : updated_region) { |
| 137 frame_painter->updated_region()->AddRect(rect); | 137 frame_painter->updated_region()->AddRect(rect); |
| 138 } | 138 } |
| 139 capturer->CaptureFrame(); | 139 capturer->CaptureFrame(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Executes a ScreenCapturerDifferWrapper::Capture(), if updated_region() is not | 142 // Executes a DesktopCapturerDifferWrapper::Capture(), if updated_region() is |
| 143 // set, this function will reset ScreenCapturerDifferWrapper internal | 143 // not set, this function will reset DesktopCapturerDifferWrapper internal |
| 144 // DesktopFrame into white. | 144 // DesktopFrame into black. |
| 145 void ExecuteCapturer(ScreenCapturerDifferWrapper* capturer, | 145 void ExecuteCapturer(DesktopCapturerDifferWrapper* capturer, |
| 146 MockScreenCapturerCallback* callback) { | 146 MockDesktopCapturerCallback* callback) { |
| 147 EXPECT_CALL(*callback, | 147 EXPECT_CALL(*callback, |
| 148 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) | 148 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) |
| 149 .Times(1); | 149 .Times(1); |
| 150 capturer->CaptureFrame(); | 150 capturer->CaptureFrame(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ExecuteDifferWrapperTest(bool with_hints, | 153 void ExecuteDifferWrapperTest(bool with_hints, |
| 154 bool enlarge_updated_region, | 154 bool enlarge_updated_region, |
| 155 bool random_updated_region, | 155 bool random_updated_region, |
| 156 bool check_result) { | 156 bool check_result) { |
| 157 const bool updated_region_should_exactly_match = | 157 const bool updated_region_should_exactly_match = |
| 158 with_hints && !enlarge_updated_region && !random_updated_region; | 158 with_hints && !enlarge_updated_region && !random_updated_region; |
| 159 BlackWhiteDesktopFramePainter frame_painter; | 159 BlackWhiteDesktopFramePainter frame_painter; |
| 160 PainterDesktopFrameGenerator frame_generator; | 160 PainterDesktopFrameGenerator frame_generator; |
| 161 frame_generator.set_desktop_frame_painter(&frame_painter); | 161 frame_generator.set_desktop_frame_painter(&frame_painter); |
| 162 std::unique_ptr<FakeScreenCapturer> fake(new FakeScreenCapturer()); | 162 std::unique_ptr<FakeDesktopCapturer<>> fake(new FakeDesktopCapturer<>()); |
| 163 fake->set_frame_generator(&frame_generator); | 163 fake->set_frame_generator(&frame_generator); |
| 164 ScreenCapturerDifferWrapper capturer(std::move(fake)); | 164 DesktopCapturerDifferWrapper capturer(std::move(fake)); |
| 165 MockScreenCapturerCallback callback; | 165 MockDesktopCapturerCallback callback; |
| 166 frame_generator.set_provide_updated_region_hints(with_hints); | 166 frame_generator.set_provide_updated_region_hints(with_hints); |
| 167 frame_generator.set_enlarge_updated_region(enlarge_updated_region); | 167 frame_generator.set_enlarge_updated_region(enlarge_updated_region); |
| 168 frame_generator.set_add_random_updated_region(random_updated_region); | 168 frame_generator.set_add_random_updated_region(random_updated_region); |
| 169 | 169 |
| 170 capturer.Start(&callback); | 170 capturer.Start(&callback); |
| 171 | 171 |
| 172 EXPECT_CALL(callback, | 172 EXPECT_CALL(callback, |
| 173 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) | 173 OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, testing::_)) |
| 174 .Times(1) | 174 .Times(1) |
| 175 .WillOnce(testing::Invoke([](DesktopCapturer::Result result, | 175 .WillOnce(testing::Invoke([](DesktopCapturer::Result result, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 updated_region.push_back(DesktopRect::MakeLTRB(left, top, right, bottom)); | 217 updated_region.push_back(DesktopRect::MakeLTRB(left, top, right, bottom)); |
| 218 } | 218 } |
| 219 ExecuteDifferWrapperCase(&frame_painter, &capturer, &callback, | 219 ExecuteDifferWrapperCase(&frame_painter, &capturer, &callback, |
| 220 updated_region, check_result, | 220 updated_region, check_result, |
| 221 updated_region_should_exactly_match); | 221 updated_region_should_exactly_match); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace | 225 } // namespace |
| 226 | 226 |
| 227 TEST(ScreenCapturerDifferWrapperTest, CaptureWithoutHints) { | 227 TEST(DesktopCapturerDifferWrapperTest, CaptureWithoutHints) { |
| 228 ExecuteDifferWrapperTest(false, false, false, true); | 228 ExecuteDifferWrapperTest(false, false, false, true); |
| 229 } | 229 } |
| 230 | 230 |
| 231 TEST(ScreenCapturerDifferWrapperTest, CaptureWithHints) { | 231 TEST(DesktopCapturerDifferWrapperTest, CaptureWithHints) { |
| 232 ExecuteDifferWrapperTest(true, false, false, true); | 232 ExecuteDifferWrapperTest(true, false, false, true); |
| 233 } | 233 } |
| 234 | 234 |
| 235 TEST(ScreenCapturerDifferWrapperTest, CaptureWithEnlargedHints) { | 235 TEST(DesktopCapturerDifferWrapperTest, CaptureWithEnlargedHints) { |
| 236 ExecuteDifferWrapperTest(true, true, false, true); | 236 ExecuteDifferWrapperTest(true, true, false, true); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST(ScreenCapturerDifferWrapperTest, CaptureWithRandomHints) { | 239 TEST(DesktopCapturerDifferWrapperTest, CaptureWithRandomHints) { |
| 240 ExecuteDifferWrapperTest(true, false, true, true); | 240 ExecuteDifferWrapperTest(true, false, true, true); |
| 241 } | 241 } |
| 242 | 242 |
| 243 TEST(ScreenCapturerDifferWrapperTest, CaptureWithEnlargedAndRandomHints) { | 243 TEST(DesktopCapturerDifferWrapperTest, CaptureWithEnlargedAndRandomHints) { |
| 244 ExecuteDifferWrapperTest(true, true, true, true); | 244 ExecuteDifferWrapperTest(true, true, true, true); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // When hints are provided, ScreenCapturerDifferWrapper has a slightly better | 247 // When hints are provided, DesktopCapturerDifferWrapper has a slightly better |
| 248 // performance in current configuration, but not so significant. Following is | 248 // performance in current configuration, but not so significant. Following is |
| 249 // one run result. | 249 // one run result. |
| 250 // [ RUN ] DISABLED_CaptureWithoutHintsPerf | 250 // [ RUN ] DISABLED_CaptureWithoutHintsPerf |
| 251 // [ OK ] DISABLED_CaptureWithoutHintsPerf (7118 ms) | 251 // [ OK ] DISABLED_CaptureWithoutHintsPerf (7118 ms) |
| 252 // [ RUN ] DISABLED_CaptureWithHintsPerf | 252 // [ RUN ] DISABLED_CaptureWithHintsPerf |
| 253 // [ OK ] DISABLED_CaptureWithHintsPerf (5580 ms) | 253 // [ OK ] DISABLED_CaptureWithHintsPerf (5580 ms) |
| 254 // [ RUN ] DISABLED_CaptureWithEnlargedHintsPerf | 254 // [ RUN ] DISABLED_CaptureWithEnlargedHintsPerf |
| 255 // [ OK ] DISABLED_CaptureWithEnlargedHintsPerf (5974 ms) | 255 // [ OK ] DISABLED_CaptureWithEnlargedHintsPerf (5974 ms) |
| 256 // [ RUN ] DISABLED_CaptureWithRandomHintsPerf | 256 // [ RUN ] DISABLED_CaptureWithRandomHintsPerf |
| 257 // [ OK ] DISABLED_CaptureWithRandomHintsPerf (6184 ms) | 257 // [ OK ] DISABLED_CaptureWithRandomHintsPerf (6184 ms) |
| 258 // [ RUN ] DISABLED_CaptureWithEnlargedAndRandomHintsPerf | 258 // [ RUN ] DISABLED_CaptureWithEnlargedAndRandomHintsPerf |
| 259 // [ OK ] DISABLED_CaptureWithEnlargedAndRandomHintsPerf (6347 ms) | 259 // [ OK ] DISABLED_CaptureWithEnlargedAndRandomHintsPerf (6347 ms) |
| 260 TEST(ScreenCapturerDifferWrapperTest, DISABLED_CaptureWithoutHintsPerf) { | 260 TEST(DesktopCapturerDifferWrapperTest, DISABLED_CaptureWithoutHintsPerf) { |
| 261 int64_t started = rtc::TimeMillis(); | 261 int64_t started = rtc::TimeMillis(); |
| 262 ExecuteDifferWrapperTest(false, false, false, false); | 262 ExecuteDifferWrapperTest(false, false, false, false); |
| 263 ASSERT_LE(rtc::TimeMillis() - started, 15000); | 263 ASSERT_LE(rtc::TimeMillis() - started, 15000); |
| 264 } | 264 } |
| 265 | 265 |
| 266 TEST(ScreenCapturerDifferWrapperTest, DISABLED_CaptureWithHintsPerf) { | 266 TEST(DesktopCapturerDifferWrapperTest, DISABLED_CaptureWithHintsPerf) { |
| 267 int64_t started = rtc::TimeMillis(); | 267 int64_t started = rtc::TimeMillis(); |
| 268 ExecuteDifferWrapperTest(true, false, false, false); | 268 ExecuteDifferWrapperTest(true, false, false, false); |
| 269 ASSERT_LE(rtc::TimeMillis() - started, 15000); | 269 ASSERT_LE(rtc::TimeMillis() - started, 15000); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST(ScreenCapturerDifferWrapperTest, DISABLED_CaptureWithEnlargedHintsPerf) { | 272 TEST(DesktopCapturerDifferWrapperTest, DISABLED_CaptureWithEnlargedHintsPerf) { |
| 273 int64_t started = rtc::TimeMillis(); | 273 int64_t started = rtc::TimeMillis(); |
| 274 ExecuteDifferWrapperTest(true, true, false, false); | 274 ExecuteDifferWrapperTest(true, true, false, false); |
| 275 ASSERT_LE(rtc::TimeMillis() - started, 15000); | 275 ASSERT_LE(rtc::TimeMillis() - started, 15000); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST(ScreenCapturerDifferWrapperTest, DISABLED_CaptureWithRandomHintsPerf) { | 278 TEST(DesktopCapturerDifferWrapperTest, DISABLED_CaptureWithRandomHintsPerf) { |
| 279 int64_t started = rtc::TimeMillis(); | 279 int64_t started = rtc::TimeMillis(); |
| 280 ExecuteDifferWrapperTest(true, false, true, false); | 280 ExecuteDifferWrapperTest(true, false, true, false); |
| 281 ASSERT_LE(rtc::TimeMillis() - started, 15000); | 281 ASSERT_LE(rtc::TimeMillis() - started, 15000); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST(ScreenCapturerDifferWrapperTest, | 284 TEST(DesktopCapturerDifferWrapperTest, |
| 285 DISABLED_CaptureWithEnlargedAndRandomHintsPerf) { | 285 DISABLED_CaptureWithEnlargedAndRandomHintsPerf) { |
| 286 int64_t started = rtc::TimeMillis(); | 286 int64_t started = rtc::TimeMillis(); |
| 287 ExecuteDifferWrapperTest(true, true, true, false); | 287 ExecuteDifferWrapperTest(true, true, true, false); |
| 288 ASSERT_LE(rtc::TimeMillis() - started, 15000); | 288 ASSERT_LE(rtc::TimeMillis() - started, 15000); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace webrtc | 291 } // namespace webrtc |
| OLD | NEW |