OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
11 #include "remoting/base/encoder.h" | 11 #include "remoting/base/encoder.h" |
| 12 #include "remoting/base/encoder_verbatim.h" |
| 13 #include "remoting/base/encoder_vp8.h" |
| 14 #include "remoting/base/encoder_zlib.h" |
12 #include "remoting/host/chromoting_host_context.h" | 15 #include "remoting/host/chromoting_host_context.h" |
13 #include "remoting/host/capturer.h" | 16 #include "remoting/host/capturer.h" |
14 #include "remoting/host/event_executor.h" | 17 #include "remoting/host/event_executor.h" |
15 #include "remoting/host/host_config.h" | 18 #include "remoting/host/host_config.h" |
16 #include "remoting/host/session_manager.h" | 19 #include "remoting/host/session_manager.h" |
17 #include "remoting/protocol/jingle_chromotocol_server.h" | 20 #include "remoting/protocol/jingle_chromotocol_server.h" |
| 21 #include "remoting/protocol/chromotocol_config.h" |
18 | 22 |
19 namespace remoting { | 23 namespace remoting { |
20 | 24 |
21 ChromotingHost::ChromotingHost(ChromotingHostContext* context, | 25 ChromotingHost::ChromotingHost(ChromotingHostContext* context, |
22 MutableHostConfig* config, | 26 MutableHostConfig* config, |
23 Capturer* capturer, | 27 Capturer* capturer, |
24 Encoder* encoder, | |
25 EventExecutor* executor) | 28 EventExecutor* executor) |
26 : context_(context), | 29 : context_(context), |
27 config_(config), | 30 config_(config), |
28 capturer_(capturer), | 31 capturer_(capturer), |
29 encoder_(encoder), | |
30 executor_(executor), | 32 executor_(executor), |
31 state_(kInitial) { | 33 state_(kInitial) { |
32 } | 34 } |
33 | 35 |
34 ChromotingHost::~ChromotingHost() { | 36 ChromotingHost::~ChromotingHost() { |
35 } | 37 } |
36 | 38 |
37 void ChromotingHost::Start(Task* shutdown_task) { | 39 void ChromotingHost::Start(Task* shutdown_task) { |
38 if (MessageLoop::current() != context_->main_message_loop()) { | 40 if (MessageLoop::current() != context_->main_message_loop()) { |
39 context_->main_message_loop()->PostTask( | 41 context_->main_message_loop()->PostTask( |
(...skipping 93 matching lines...) Loading... |
133 | 135 |
134 // This method is called if a client is connected to this object. | 136 // This method is called if a client is connected to this object. |
135 void ChromotingHost::OnClientConnected(ClientConnection* client) { | 137 void ChromotingHost::OnClientConnected(ClientConnection* client) { |
136 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 138 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
137 | 139 |
138 // Create a new RecordSession if there was none. | 140 // Create a new RecordSession if there was none. |
139 if (!session_.get()) { | 141 if (!session_.get()) { |
140 // Then we create a SessionManager passing the message loops that | 142 // Then we create a SessionManager passing the message loops that |
141 // it should run on. | 143 // it should run on. |
142 DCHECK(capturer_.get()); | 144 DCHECK(capturer_.get()); |
143 DCHECK(encoder_.get()); | 145 |
| 146 Encoder* encoder = CreateEncoder(client->connection()->config()); |
| 147 |
144 session_ = new SessionManager(context_->capture_message_loop(), | 148 session_ = new SessionManager(context_->capture_message_loop(), |
145 context_->encode_message_loop(), | 149 context_->encode_message_loop(), |
146 context_->main_message_loop(), | 150 context_->main_message_loop(), |
147 capturer_.get(), | 151 capturer_.release(), |
148 encoder_.get()); | 152 encoder); |
149 } | 153 } |
150 | 154 |
151 // Immediately add the client and start the session. | 155 // Immediately add the client and start the session. |
152 session_->AddClient(client); | 156 session_->AddClient(client); |
153 session_->Start(); | 157 session_->Start(); |
154 VLOG(1) << "Session manager started"; | 158 VLOG(1) << "Session manager started"; |
155 } | 159 } |
156 | 160 |
157 void ChromotingHost::OnClientDisconnected(ClientConnection* client) { | 161 void ChromotingHost::OnClientDisconnected(ClientConnection* client) { |
158 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 162 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
(...skipping 119 matching lines...) Loading... |
278 // If we accept the connected then create a client object and set the | 282 // If we accept the connected then create a client object and set the |
279 // callback. | 283 // callback. |
280 client_ = new ClientConnection(context_->main_message_loop(), this); | 284 client_ = new ClientConnection(context_->main_message_loop(), this); |
281 client_->Init(connection); | 285 client_->Init(connection); |
282 } | 286 } |
283 | 287 |
284 void ChromotingHost::OnServerClosed() { | 288 void ChromotingHost::OnServerClosed() { |
285 // Don't need to do anything here. | 289 // Don't need to do anything here. |
286 } | 290 } |
287 | 291 |
| 292 // TODO(sergeyu): Move this to SessionManager? |
| 293 Encoder* ChromotingHost::CreateEncoder(const ChromotocolConfig* config) { |
| 294 const ChannelConfig& video_config = config->video_config(); |
| 295 |
| 296 if (video_config.codec == ChannelConfig::CODEC_VERBATIM) { |
| 297 return new remoting::EncoderVerbatim(); |
| 298 } else if (video_config.codec == ChannelConfig::CODEC_ZIP) { |
| 299 return new remoting::EncoderZlib(); |
| 300 } |
| 301 // TODO(sergeyu): Enable VP8 on ARM builds. |
| 302 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 303 else if (video_config.codec == ChannelConfig::CODEC_VP8) { |
| 304 return new remoting::EncoderVp8(); |
| 305 } |
| 306 #endif |
| 307 |
| 308 return NULL; |
| 309 } |
| 310 |
| 311 |
288 } // namespace remoting | 312 } // namespace remoting |
OLD | NEW |