OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/test/it2me_standalone_host.h" |
| 6 |
| 7 #include <iostream> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" |
| 15 #include "remoting/base/auto_thread_task_runner.h" |
| 16 #include "remoting/host/chromoting_host_context.h" |
| 17 #include "remoting/host/host_extension.h" |
| 18 #include "remoting/protocol/pairing_registry.h" |
| 19 #include "remoting/protocol/protocol_mock_objects.h" |
| 20 #include "remoting/protocol/session_config.h" |
| 21 |
| 22 namespace remoting { |
| 23 namespace test { |
| 24 |
| 25 namespace { |
| 26 |
| 27 void OutputStubs(const CounterStubs* stubs) { |
| 28 std::cout << *stubs; |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 using ::remoting::protocol::MockSession; |
| 34 |
| 35 It2MeStandaloneHost::It2MeStandaloneHost() |
| 36 : context_(ChromotingHostContext::Create( |
| 37 new AutoThreadTaskRunner( |
| 38 message_loop_.task_runner(), run_loop_.QuitClosure()))), |
| 39 factory_(context_->file_task_runner(), |
| 40 context_->video_capture_task_runner(), |
| 41 context_->input_task_runner(), |
| 42 context_->ui_task_runner()), |
| 43 connection_(base::WrapUnique(new testing::NiceMock<MockSession>())), |
| 44 session_jid_("user@domain/rest-of-jid"), |
| 45 #if defined(OS_LINUX) |
| 46 // We cannot support audio capturing for linux, since a pipe name is |
| 47 // needed to initialize AudioCapturerLinux. |
| 48 config_(protocol::SessionConfig::ForTest()), |
| 49 #else |
| 50 config_(protocol::SessionConfig::ForTestWithAudio()), |
| 51 #endif |
| 52 stubs_(&connection_) { |
| 53 factory_.set_enable_user_interface(false); |
| 54 EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), jid()) |
| 55 .WillRepeatedly(testing::ReturnRef(session_jid_)); |
| 56 EXPECT_CALL(*static_cast<MockSession*>(connection_.session()), config()) |
| 57 .WillRepeatedly(testing::ReturnRef(*config_)); |
| 58 connection_.set_audio_stub(&stubs_.audio_stub()); |
| 59 connection_.set_video_stub(&stubs_.video_stub()); |
| 60 connection_.set_client_stub(&stubs_.client_stub()); |
| 61 connection_.set_host_stub(&stubs_.host_stub()); |
| 62 connection_.set_video_encode_task_runner( |
| 63 context_->video_encode_task_runner()); |
| 64 } |
| 65 |
| 66 It2MeStandaloneHost::~It2MeStandaloneHost() {} |
| 67 |
| 68 void It2MeStandaloneHost::Run() { |
| 69 context_->file_task_runner()->PostTask( |
| 70 FROM_HERE, |
| 71 base::Bind(&It2MeStandaloneHost::Connect, base::Unretained(this))); |
| 72 run_loop_.Run(); |
| 73 } |
| 74 |
| 75 void It2MeStandaloneHost::StartToOutputToStdout() { |
| 76 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), |
| 77 base::Bind(&OutputStubs, &stubs_)); |
| 78 } |
| 79 |
| 80 void It2MeStandaloneHost::Connect() { |
| 81 session_.reset(new ClientSession( |
| 82 &handler_, |
| 83 context_->audio_task_runner(), |
| 84 std::unique_ptr<protocol::ConnectionToClient>(&connection_), |
| 85 &factory_, |
| 86 base::TimeDelta(), |
| 87 scoped_refptr<protocol::PairingRegistry>(), |
| 88 std::vector<HostExtension*>())); |
| 89 session_->OnConnectionAuthenticated(&connection_); |
| 90 session_->OnConnectionChannelsConnected(&connection_); |
| 91 session_->CreateVideoStreams(&connection_); |
| 92 } |
| 93 |
| 94 } // namespace test |
| 95 } // namespace remoting |
OLD | NEW |