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

Side by Side Diff: remoting/host/video_scheduler_unittest.cc

Issue 455073004: Switch DesktopEnvironment to return a DesktopCapturer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove ShapedDesktopCapturer::Create() Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/video_scheduler.cc ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/video_scheduler.h" 5 #include "remoting/host/video_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "remoting/base/auto_thread.h" 11 #include "remoting/base/auto_thread.h"
12 #include "remoting/base/auto_thread_task_runner.h" 12 #include "remoting/base/auto_thread_task_runner.h"
13 #include "remoting/codec/video_encoder.h" 13 #include "remoting/codec/video_encoder.h"
14 #include "remoting/codec/video_encoder_verbatim.h" 14 #include "remoting/codec/video_encoder_verbatim.h"
15 #include "remoting/host/fake_desktop_capturer.h"
15 #include "remoting/host/fake_mouse_cursor_monitor.h" 16 #include "remoting/host/fake_mouse_cursor_monitor.h"
16 #include "remoting/host/fake_screen_capturer.h"
17 #include "remoting/host/host_mock_objects.h" 17 #include "remoting/host/host_mock_objects.h"
18 #include "remoting/proto/control.pb.h" 18 #include "remoting/proto/control.pb.h"
19 #include "remoting/proto/video.pb.h" 19 #include "remoting/proto/video.pb.h"
20 #include "remoting/protocol/protocol_mock_objects.h" 20 #include "remoting/protocol/protocol_mock_objects.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 23 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
24 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" 24 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
25 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h" 25 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h"
26 26
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 virtual ~ThreadCheckVideoEncoder() { 85 virtual ~ThreadCheckVideoEncoder() {
86 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 86 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
87 } 87 }
88 88
89 private: 89 private:
90 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 90 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
91 91
92 DISALLOW_COPY_AND_ASSIGN(ThreadCheckVideoEncoder); 92 DISALLOW_COPY_AND_ASSIGN(ThreadCheckVideoEncoder);
93 }; 93 };
94 94
95 class ThreadCheckScreenCapturer : public FakeScreenCapturer { 95 class ThreadCheckDesktopCapturer : public FakeDesktopCapturer {
96 public: 96 public:
97 ThreadCheckScreenCapturer( 97 ThreadCheckDesktopCapturer(
98 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 98 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
99 : task_runner_(task_runner) { 99 : task_runner_(task_runner) {
100 } 100 }
101 virtual ~ThreadCheckScreenCapturer() { 101 virtual ~ThreadCheckDesktopCapturer() {
102 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 102 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
103 } 103 }
104 104
105 private: 105 private:
106 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 106 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
107 107
108 DISALLOW_COPY_AND_ASSIGN(ThreadCheckScreenCapturer); 108 DISALLOW_COPY_AND_ASSIGN(ThreadCheckDesktopCapturer);
109 }; 109 };
110 110
111 class ThreadCheckMouseCursorMonitor : public FakeMouseCursorMonitor { 111 class ThreadCheckMouseCursorMonitor : public FakeMouseCursorMonitor {
112 public: 112 public:
113 ThreadCheckMouseCursorMonitor( 113 ThreadCheckMouseCursorMonitor(
114 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 114 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
115 : task_runner_(task_runner) { 115 : task_runner_(task_runner) {
116 } 116 }
117 virtual ~ThreadCheckMouseCursorMonitor() { 117 virtual ~ThreadCheckMouseCursorMonitor() {
118 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 118 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
119 } 119 }
120 120
121 private: 121 private:
122 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 122 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
123 123
124 DISALLOW_COPY_AND_ASSIGN(ThreadCheckMouseCursorMonitor); 124 DISALLOW_COPY_AND_ASSIGN(ThreadCheckMouseCursorMonitor);
125 }; 125 };
126 126
127 class VideoSchedulerTest : public testing::Test { 127 class VideoSchedulerTest : public testing::Test {
128 public: 128 public:
129 VideoSchedulerTest(); 129 VideoSchedulerTest();
130 130
131 virtual void SetUp() OVERRIDE; 131 virtual void SetUp() OVERRIDE;
132 virtual void TearDown() OVERRIDE; 132 virtual void TearDown() OVERRIDE;
133 133
134 void StartVideoScheduler( 134 void StartVideoScheduler(
135 scoped_ptr<webrtc::ScreenCapturer> capturer, 135 scoped_ptr<webrtc::DesktopCapturer> capturer,
136 scoped_ptr<VideoEncoder> encoder, 136 scoped_ptr<VideoEncoder> encoder,
137 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor); 137 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor);
138 void StopVideoScheduler(); 138 void StopVideoScheduler();
139 139
140 // webrtc::ScreenCapturer mocks. 140 // webrtc::DesktopCapturer mocks.
141 void OnCapturerStart(webrtc::ScreenCapturer::Callback* callback); 141 void OnCapturerStart(webrtc::DesktopCapturer::Callback* callback);
142 void OnCaptureFrame(const webrtc::DesktopRegion& region); 142 void OnCaptureFrame(const webrtc::DesktopRegion& region);
143
144 // webrtc::MouseCursorMonitor mocks.
143 void OnMouseCursorMonitorInit( 145 void OnMouseCursorMonitorInit(
144 webrtc::MouseCursorMonitor::Callback* callback, 146 webrtc::MouseCursorMonitor::Callback* callback,
145 webrtc::MouseCursorMonitor::Mode mode); 147 webrtc::MouseCursorMonitor::Mode mode);
146 void OnCaptureMouse(); 148 void OnCaptureMouse();
147 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape); 149 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape);
148 150
149 protected: 151 protected:
150 base::MessageLoop message_loop_; 152 base::MessageLoop message_loop_;
151 base::RunLoop run_loop_; 153 base::RunLoop run_loop_;
152 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_; 154 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_;
153 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_; 155 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_;
154 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; 156 scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
155 scoped_refptr<VideoScheduler> scheduler_; 157 scoped_refptr<VideoScheduler> scheduler_;
156 158
157 MockClientStub client_stub_; 159 MockClientStub client_stub_;
158 MockVideoStub video_stub_; 160 MockVideoStub video_stub_;
159 161
160 // Points to the callback passed to webrtc::ScreenCapturer::Start(). 162 // Points to the callback passed to webrtc::DesktopCapturer::Start().
161 webrtc::ScreenCapturer::Callback* capturer_callback_; 163 webrtc::DesktopCapturer::Callback* capturer_callback_;
162 164
163 // Points to the callback passed to webrtc::MouseCursor::Init(). 165 // Points to the callback passed to webrtc::MouseCursor::Init().
164 webrtc::MouseCursorMonitor::Callback* mouse_monitor_callback_; 166 webrtc::MouseCursorMonitor::Callback* mouse_monitor_callback_;
165 167
166 private: 168 private:
167 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); 169 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest);
168 }; 170 };
169 171
170 VideoSchedulerTest::VideoSchedulerTest() 172 VideoSchedulerTest::VideoSchedulerTest()
171 : capturer_callback_(NULL), 173 : capturer_callback_(NULL),
(...skipping 11 matching lines...) Expand all
183 // Release the task runners, so that the test can quit. 185 // Release the task runners, so that the test can quit.
184 capture_task_runner_ = NULL; 186 capture_task_runner_ = NULL;
185 encode_task_runner_ = NULL; 187 encode_task_runner_ = NULL;
186 main_task_runner_ = NULL; 188 main_task_runner_ = NULL;
187 189
188 // Run the MessageLoop until everything has torn down. 190 // Run the MessageLoop until everything has torn down.
189 run_loop_.Run(); 191 run_loop_.Run();
190 } 192 }
191 193
192 void VideoSchedulerTest::StartVideoScheduler( 194 void VideoSchedulerTest::StartVideoScheduler(
193 scoped_ptr<webrtc::ScreenCapturer> capturer, 195 scoped_ptr<webrtc::DesktopCapturer> capturer,
194 scoped_ptr<VideoEncoder> encoder, 196 scoped_ptr<VideoEncoder> encoder,
195 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor) { 197 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor) {
196 scheduler_ = new VideoScheduler( 198 scheduler_ = new VideoScheduler(
197 capture_task_runner_, 199 capture_task_runner_,
198 encode_task_runner_, 200 encode_task_runner_,
199 main_task_runner_, 201 main_task_runner_,
200 capturer.Pass(), 202 capturer.Pass(),
201 mouse_monitor.Pass(), 203 mouse_monitor.Pass(),
202 encoder.Pass(), 204 encoder.Pass(),
203 &client_stub_, 205 &client_stub_,
204 &video_stub_); 206 &video_stub_);
205 scheduler_->Start(); 207 scheduler_->Start();
206 } 208 }
207 209
208 void VideoSchedulerTest::StopVideoScheduler() { 210 void VideoSchedulerTest::StopVideoScheduler() {
209 scheduler_->Stop(); 211 scheduler_->Stop();
210 scheduler_ = NULL; 212 scheduler_ = NULL;
211 } 213 }
212 214
213 void VideoSchedulerTest::OnCapturerStart( 215 void VideoSchedulerTest::OnCapturerStart(
214 webrtc::ScreenCapturer::Callback* callback) { 216 webrtc::DesktopCapturer::Callback* callback) {
215 EXPECT_FALSE(capturer_callback_); 217 EXPECT_FALSE(capturer_callback_);
216 EXPECT_TRUE(callback); 218 EXPECT_TRUE(callback);
217 219
218 capturer_callback_ = callback; 220 capturer_callback_ = callback;
219 } 221 }
220 222
221 void VideoSchedulerTest::OnCaptureFrame(const webrtc::DesktopRegion& region) { 223 void VideoSchedulerTest::OnCaptureFrame(const webrtc::DesktopRegion& region) {
222 scoped_ptr<webrtc::DesktopFrame> frame( 224 scoped_ptr<webrtc::DesktopFrame> frame(
223 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(kWidth, kHeight))); 225 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(kWidth, kHeight)));
224 frame->mutable_updated_region()->SetRect( 226 frame->mutable_updated_region()->SetRect(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 FinishSend(), 310 FinishSend(),
309 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) 311 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler)))
310 .RetiresOnSaturation(); 312 .RetiresOnSaturation();
311 313
312 EXPECT_CALL(client_stub_, SetCursorShape(_)) 314 EXPECT_CALL(client_stub_, SetCursorShape(_))
313 .WillOnce(Invoke(this, &VideoSchedulerTest::SetCursorShape)); 315 .WillOnce(Invoke(this, &VideoSchedulerTest::SetCursorShape));
314 316
315 // Start video frame capture. 317 // Start video frame capture.
316 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor( 318 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor(
317 new FakeMouseCursorMonitor()); 319 new FakeMouseCursorMonitor());
318 StartVideoScheduler(capturer.PassAs<webrtc::ScreenCapturer>(), 320 StartVideoScheduler(capturer.PassAs<webrtc::DesktopCapturer>(),
319 encoder.PassAs<VideoEncoder>(), 321 encoder.PassAs<VideoEncoder>(),
320 cursor_monitor.PassAs<webrtc::MouseCursorMonitor>()); 322 cursor_monitor.PassAs<webrtc::MouseCursorMonitor>());
321 323
322 // Run until there are no more pending tasks from the VideoScheduler. 324 // Run until there are no more pending tasks from the VideoScheduler.
323 // Otherwise, a lingering frame capture might attempt to trigger a capturer 325 // Otherwise, a lingering frame capture might attempt to trigger a capturer
324 // expectation action and crash. 326 // expectation action and crash.
325 base::RunLoop().RunUntilIdle(); 327 base::RunLoop().RunUntilIdle();
326 } 328 }
327 329
328 // Verify that the capturer, encoder and mouse monitor are torn down on the 330 // Verify that the capturer, encoder and mouse monitor are torn down on the
329 // correct threads. 331 // correct threads.
330 TEST_F(VideoSchedulerTest, DeleteOnThreads) { 332 TEST_F(VideoSchedulerTest, DeleteOnThreads) {
331 capture_task_runner_ = AutoThread::Create("capture", main_task_runner_); 333 capture_task_runner_ = AutoThread::Create("capture", main_task_runner_);
332 encode_task_runner_ = AutoThread::Create("encode", main_task_runner_); 334 encode_task_runner_ = AutoThread::Create("encode", main_task_runner_);
333 335
334 scoped_ptr<webrtc::ScreenCapturer> capturer( 336 scoped_ptr<webrtc::DesktopCapturer> capturer(
335 new ThreadCheckScreenCapturer(capture_task_runner_)); 337 new ThreadCheckDesktopCapturer(capture_task_runner_));
336 scoped_ptr<VideoEncoder> encoder( 338 scoped_ptr<VideoEncoder> encoder(
337 new ThreadCheckVideoEncoder(encode_task_runner_)); 339 new ThreadCheckVideoEncoder(encode_task_runner_));
338 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor( 340 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor(
339 new ThreadCheckMouseCursorMonitor(capture_task_runner_)); 341 new ThreadCheckMouseCursorMonitor(capture_task_runner_));
340 342
341 // Start and stop the scheduler, so it will tear down the screen capturer, 343 // Start and stop the scheduler, so it will tear down the screen capturer,
342 // video encoder and mouse monitor. 344 // video encoder and mouse monitor.
343 StartVideoScheduler(capturer.Pass(), encoder.Pass(), 345 StartVideoScheduler(capturer.Pass(), encoder.Pass(),
344 mouse_cursor_monitor.Pass()); 346 mouse_cursor_monitor.Pass());
345 StopVideoScheduler(); 347 StopVideoScheduler();
346 } 348 }
347 349
348 } // namespace remoting 350 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/video_scheduler.cc ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698