OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 using ::testing::_; | 28 using ::testing::_; |
29 | 29 |
30 const int kTestSharedMemoryId = 123; | 30 const int kTestSharedMemoryId = 123; |
31 | 31 |
32 namespace webrtc { | 32 namespace webrtc { |
33 | 33 |
34 class ScreenCapturerTest : public testing::Test { | 34 class ScreenCapturerTest : public testing::Test { |
35 public: | 35 public: |
36 void SetUp() override { | 36 void SetUp() override { |
37 capturer_.reset( | 37 capturer_ = DesktopCapturer::CreateScreenCapturer( |
38 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); | 38 DesktopCaptureOptions::CreateDefault()); |
39 } | 39 } |
40 | 40 |
41 protected: | 41 protected: |
42 #if defined(WEBRTC_WIN) | 42 #if defined(WEBRTC_WIN) |
43 // Enable allow_directx_capturer in DesktopCaptureOptions, but let | 43 // Enable allow_directx_capturer in DesktopCaptureOptions, but let |
44 // ScreenCapturer::Create to decide whether a DirectX capturer should be used. | 44 // DesktopCapturer::CreateScreenCapturer to decide whether a DirectX capturer |
| 45 // should be used. |
45 void MaybeCreateDirectxCapturer() { | 46 void MaybeCreateDirectxCapturer() { |
46 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 47 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
47 options.set_allow_directx_capturer(true); | 48 options.set_allow_directx_capturer(true); |
48 capturer_.reset(ScreenCapturer::Create(options)); | 49 capturer_ = DesktopCapturer::CreateScreenCapturer(options); |
49 } | 50 } |
50 | 51 |
51 bool CreateDirectxCapturer() { | 52 bool CreateDirectxCapturer() { |
52 if (!ScreenCapturerWinDirectx::IsSupported()) { | 53 if (!ScreenCapturerWinDirectx::IsSupported()) { |
53 LOG(LS_WARNING) << "Directx capturer is not supported"; | 54 LOG(LS_WARNING) << "Directx capturer is not supported"; |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 MaybeCreateDirectxCapturer(); | 58 MaybeCreateDirectxCapturer(); |
58 return true; | 59 return true; |
59 } | 60 } |
60 | 61 |
61 void CreateMagnifierCapturer() { | 62 void CreateMagnifierCapturer() { |
62 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); | 63 DesktopCaptureOptions options(DesktopCaptureOptions::CreateDefault()); |
63 options.set_allow_use_magnification_api(true); | 64 options.set_allow_use_magnification_api(true); |
64 capturer_.reset(ScreenCapturer::Create(options)); | 65 capturer_ = DesktopCapturer::CreateScreenCapturer(options); |
65 } | 66 } |
66 #endif // defined(WEBRTC_WIN) | 67 #endif // defined(WEBRTC_WIN) |
67 | 68 |
68 std::unique_ptr<ScreenCapturer> capturer_; | 69 std::unique_ptr<DesktopCapturer> capturer_; |
69 MockScreenCapturerCallback callback_; | 70 MockScreenCapturerCallback callback_; |
70 }; | 71 }; |
71 | 72 |
72 class FakeSharedMemory : public SharedMemory { | 73 class FakeSharedMemory : public SharedMemory { |
73 public: | 74 public: |
74 FakeSharedMemory(char* buffer, size_t size) | 75 FakeSharedMemory(char* buffer, size_t size) |
75 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), | 76 : SharedMemory(buffer, size, 0, kTestSharedMemoryId), |
76 buffer_(buffer) { | 77 buffer_(buffer) { |
77 } | 78 } |
78 virtual ~FakeSharedMemory() { | 79 virtual ~FakeSharedMemory() { |
(...skipping 16 matching lines...) Expand all Loading... |
95 | 96 |
96 private: | 97 private: |
97 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); | 98 RTC_DISALLOW_COPY_AND_ASSIGN(FakeSharedMemoryFactory); |
98 }; | 99 }; |
99 | 100 |
100 ACTION_P(SaveUniquePtrArg, dest) { | 101 ACTION_P(SaveUniquePtrArg, dest) { |
101 *dest = std::move(*arg1); | 102 *dest = std::move(*arg1); |
102 } | 103 } |
103 | 104 |
104 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { | 105 TEST_F(ScreenCapturerTest, GetScreenListAndSelectScreen) { |
105 webrtc::ScreenCapturer::ScreenList screens; | 106 webrtc::DesktopCapturer::SourceList screens; |
106 EXPECT_TRUE(capturer_->GetScreenList(&screens)); | 107 EXPECT_TRUE(capturer_->GetSourceList(&screens)); |
107 for (webrtc::ScreenCapturer::ScreenList::iterator it = screens.begin(); | 108 for (const auto& screen : screens) { |
108 it != screens.end(); ++it) { | 109 EXPECT_TRUE(capturer_->SelectSource(screen.id)); |
109 EXPECT_TRUE(capturer_->SelectScreen(it->id)); | |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 TEST_F(ScreenCapturerTest, StartCapturer) { | 113 TEST_F(ScreenCapturerTest, StartCapturer) { |
114 capturer_->Start(&callback_); | 114 capturer_->Start(&callback_); |
115 } | 115 } |
116 | 116 |
117 TEST_F(ScreenCapturerTest, Capture) { | 117 TEST_F(ScreenCapturerTest, Capture) { |
118 // Assume that Start() treats the screen as invalid initially. | 118 // Assume that Start() treats the screen as invalid initially. |
119 std::unique_ptr<DesktopFrame> frame; | 119 std::unique_ptr<DesktopFrame> frame; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); | 200 std::unique_ptr<SharedMemoryFactory>(new FakeSharedMemoryFactory())); |
201 capturer_->CaptureFrame(); | 201 capturer_->CaptureFrame(); |
202 ASSERT_TRUE(frame); | 202 ASSERT_TRUE(frame); |
203 ASSERT_TRUE(frame->shared_memory()); | 203 ASSERT_TRUE(frame->shared_memory()); |
204 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); | 204 EXPECT_EQ(frame->shared_memory()->id(), kTestSharedMemoryId); |
205 } | 205 } |
206 | 206 |
207 #endif // defined(WEBRTC_WIN) | 207 #endif // defined(WEBRTC_WIN) |
208 | 208 |
209 } // namespace webrtc | 209 } // namespace webrtc |
OLD | NEW |