| OLD | NEW |
| 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_desktop_capturer.h" |
| 16 #include "remoting/host/fake_mouse_cursor_monitor.h" | 16 #include "remoting/host/fake_mouse_cursor_monitor.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 |
| 27 using ::remoting::protocol::MockClientStub; | 27 using ::remoting::protocol::MockClientStub; |
| 28 using ::remoting::protocol::MockVideoStub; | 28 using ::remoting::protocol::MockVideoSender; |
| 29 | 29 |
| 30 using ::testing::_; | 30 using ::testing::_; |
| 31 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
| 32 using ::testing::AnyNumber; | 32 using ::testing::AnyNumber; |
| 33 using ::testing::DeleteArg; | 33 using ::testing::DeleteArg; |
| 34 using ::testing::DoAll; | 34 using ::testing::DoAll; |
| 35 using ::testing::Expectation; | 35 using ::testing::Expectation; |
| 36 using ::testing::InSequence; | 36 using ::testing::InSequence; |
| 37 using ::testing::InvokeWithoutArgs; | 37 using ::testing::InvokeWithoutArgs; |
| 38 using ::testing::Return; | 38 using ::testing::Return; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 protected: | 150 protected: |
| 151 base::MessageLoop message_loop_; | 151 base::MessageLoop message_loop_; |
| 152 base::RunLoop run_loop_; | 152 base::RunLoop run_loop_; |
| 153 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_; | 153 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_; |
| 154 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_; | 154 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_; |
| 155 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; | 155 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; |
| 156 scoped_refptr<VideoScheduler> scheduler_; | 156 scoped_refptr<VideoScheduler> scheduler_; |
| 157 | 157 |
| 158 MockClientStub client_stub_; | 158 MockClientStub client_stub_; |
| 159 MockVideoStub video_stub_; | 159 MockVideoSender video_sender_; |
| 160 | 160 |
| 161 // Points to the callback passed to webrtc::DesktopCapturer::Start(). | 161 // Points to the callback passed to webrtc::DesktopCapturer::Start(). |
| 162 webrtc::DesktopCapturer::Callback* capturer_callback_; | 162 webrtc::DesktopCapturer::Callback* capturer_callback_; |
| 163 | 163 |
| 164 // Points to the callback passed to webrtc::MouseCursor::Init(). | 164 // Points to the callback passed to webrtc::MouseCursor::Init(). |
| 165 webrtc::MouseCursorMonitor::Callback* mouse_monitor_callback_; | 165 webrtc::MouseCursorMonitor::Callback* mouse_monitor_callback_; |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); | 168 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); |
| 169 }; | 169 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 195 scoped_ptr<VideoEncoder> encoder, | 195 scoped_ptr<VideoEncoder> encoder, |
| 196 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor) { | 196 scoped_ptr<webrtc::MouseCursorMonitor> mouse_monitor) { |
| 197 scheduler_ = new VideoScheduler( | 197 scheduler_ = new VideoScheduler( |
| 198 capture_task_runner_, | 198 capture_task_runner_, |
| 199 encode_task_runner_, | 199 encode_task_runner_, |
| 200 main_task_runner_, | 200 main_task_runner_, |
| 201 capturer.Pass(), | 201 capturer.Pass(), |
| 202 mouse_monitor.Pass(), | 202 mouse_monitor.Pass(), |
| 203 encoder.Pass(), | 203 encoder.Pass(), |
| 204 &client_stub_, | 204 &client_stub_, |
| 205 &video_stub_); | 205 &video_sender_); |
| 206 scheduler_->Start(); | 206 scheduler_->Start(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void VideoSchedulerTest::StopVideoScheduler() { | 209 void VideoSchedulerTest::StopVideoScheduler() { |
| 210 scheduler_->Stop(); | 210 scheduler_->Stop(); |
| 211 scheduler_ = nullptr; | 211 scheduler_ = nullptr; |
| 212 } | 212 } |
| 213 | 213 |
| 214 void VideoSchedulerTest::OnCapturerStart( | 214 void VideoSchedulerTest::OnCapturerStart( |
| 215 webrtc::DesktopCapturer::Callback* callback) { | 215 webrtc::DesktopCapturer::Callback* callback) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 .After(capturer_start) | 293 .After(capturer_start) |
| 294 .WillRepeatedly(Invoke(this, &VideoSchedulerTest::OnCaptureFrame)); | 294 .WillRepeatedly(Invoke(this, &VideoSchedulerTest::OnCaptureFrame)); |
| 295 | 295 |
| 296 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder()); | 296 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder()); |
| 297 | 297 |
| 298 // Expect the encoder be called. | 298 // Expect the encoder be called. |
| 299 EXPECT_CALL(*encoder, EncodePtr(_)) | 299 EXPECT_CALL(*encoder, EncodePtr(_)) |
| 300 .WillRepeatedly(FinishEncode()); | 300 .WillRepeatedly(FinishEncode()); |
| 301 | 301 |
| 302 // By default delete the arguments when ProcessVideoPacket is received. | 302 // By default delete the arguments when ProcessVideoPacket is received. |
| 303 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 303 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 304 .WillRepeatedly(FinishSend()); | 304 .WillRepeatedly(FinishSend()); |
| 305 | 305 |
| 306 // When the first ProcessVideoPacket is received we stop the VideoScheduler. | 306 // When the first ProcessVideoPacket is received we stop the VideoScheduler. |
| 307 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 307 EXPECT_CALL(video_sender_, ProcessVideoPacketPtr(_, _)) |
| 308 .WillOnce(DoAll( | 308 .WillOnce(DoAll( |
| 309 FinishSend(), | 309 FinishSend(), |
| 310 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) | 310 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) |
| 311 .RetiresOnSaturation(); | 311 .RetiresOnSaturation(); |
| 312 | 312 |
| 313 EXPECT_CALL(client_stub_, SetCursorShape(_)) | 313 EXPECT_CALL(client_stub_, SetCursorShape(_)) |
| 314 .WillOnce(Invoke(this, &VideoSchedulerTest::SetCursorShape)); | 314 .WillOnce(Invoke(this, &VideoSchedulerTest::SetCursorShape)); |
| 315 | 315 |
| 316 // Start video frame capture. | 316 // Start video frame capture. |
| 317 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor( | 317 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 338 new ThreadCheckMouseCursorMonitor(capture_task_runner_)); | 338 new ThreadCheckMouseCursorMonitor(capture_task_runner_)); |
| 339 | 339 |
| 340 // Start and stop the scheduler, so it will tear down the screen capturer, | 340 // Start and stop the scheduler, so it will tear down the screen capturer, |
| 341 // video encoder and mouse monitor. | 341 // video encoder and mouse monitor. |
| 342 StartVideoScheduler(capturer.Pass(), encoder.Pass(), | 342 StartVideoScheduler(capturer.Pass(), encoder.Pass(), |
| 343 mouse_cursor_monitor.Pass()); | 343 mouse_cursor_monitor.Pass()); |
| 344 StopVideoScheduler(); | 344 StopVideoScheduler(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 } // namespace remoting | 347 } // namespace remoting |
| OLD | NEW |