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 #if defined(OS_WIN) | |
12 #include "remoting/host/capturer_gdi.h" | |
13 #include "remoting/host/event_executor_win.h" | |
14 #elif defined(OS_LINUX) | |
15 #include "remoting/host/capturer_linux.h" | |
16 #include "remoting/host/event_executor_linux.h" | |
17 #elif defined(OS_MACOSX) | |
18 #include "remoting/host/capturer_mac.h" | |
19 #include "remoting/host/event_executor_mac.h" | |
20 #endif | |
21 #include "remoting/base/encoder.h" | 11 #include "remoting/base/encoder.h" |
22 #include "remoting/base/encoder_verbatim.h" | 12 #include "remoting/base/encoder_verbatim.h" |
23 #include "remoting/base/encoder_vp8.h" | 13 #include "remoting/base/encoder_vp8.h" |
24 #include "remoting/base/encoder_zlib.h" | 14 #include "remoting/base/encoder_zlib.h" |
15 #include "remoting/host/capturer.h" | |
25 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
17 #include "remoting/host/event_executor.h" | |
26 #include "remoting/host/host_config.h" | 18 #include "remoting/host/host_config.h" |
27 #include "remoting/host/host_stub_fake.h" | 19 #include "remoting/host/host_stub_fake.h" |
28 #include "remoting/host/session_manager.h" | 20 #include "remoting/host/session_manager.h" |
29 #include "remoting/protocol/connection_to_client.h" | 21 #include "remoting/protocol/connection_to_client.h" |
30 #include "remoting/protocol/host_stub.h" | 22 #include "remoting/protocol/host_stub.h" |
31 #include "remoting/protocol/input_stub.h" | 23 #include "remoting/protocol/input_stub.h" |
32 #include "remoting/protocol/jingle_session_manager.h" | 24 #include "remoting/protocol/jingle_session_manager.h" |
33 #include "remoting/protocol/session_config.h" | 25 #include "remoting/protocol/session_config.h" |
34 | 26 |
35 using remoting::protocol::ConnectionToClient; | 27 using remoting::protocol::ConnectionToClient; |
36 | 28 |
37 namespace remoting { | 29 namespace remoting { |
38 | 30 |
39 ChromotingHost::ChromotingHost(ChromotingHostContext* context, | 31 // static |
40 MutableHostConfig* config) | 32 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, |
41 : context_(context), | 33 MutableHostConfig* config) { |
42 config_(config), | 34 return new ChromotingHost( |
43 #if defined(OS_WIN) | 35 context, config, |
dmac
2010/11/23 01:14:57
any reason not to have these up on line 34?
Sergey Ulanov
2010/11/23 01:59:18
Done.
| |
44 capturer_(new remoting::CapturerGdi( | 36 Capturer::Create(context->main_message_loop())); |
45 context->main_message_loop())), | 37 } |
46 input_stub_(new remoting::EventExecutorWin( | 38 |
47 context->main_message_loop(), capturer_.get())), | 39 // static |
48 #elif defined(OS_LINUX) | 40 ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context, |
49 capturer_(new remoting::CapturerLinux( | 41 MutableHostConfig* config, |
50 context->main_message_loop())), | 42 Capturer* capturer) { |
51 input_stub_(new remoting::EventExecutorLinux( | 43 return new ChromotingHost(context, config, capturer); |
52 context->main_message_loop(), capturer_.get())), | |
53 #elif defined(OS_MACOSX) | |
54 capturer_(new remoting::CapturerMac( | |
55 context->main_message_loop())), | |
56 input_stub_(new remoting::EventExecutorMac( | |
57 context->main_message_loop(), capturer_.get())), | |
58 #endif | |
59 host_stub_(new HostStubFake()), | |
60 state_(kInitial) { | |
61 } | 44 } |
62 | 45 |
63 ChromotingHost::ChromotingHost(ChromotingHostContext* context, | 46 ChromotingHost::ChromotingHost(ChromotingHostContext* context, |
64 MutableHostConfig* config, Capturer* capturer) | 47 MutableHostConfig* config, Capturer* capturer) |
65 : context_(context), | 48 : context_(context), |
66 config_(config), | 49 config_(config), |
67 capturer_(capturer), | 50 capturer_(capturer), |
68 #if defined(OS_WIN) | 51 input_stub_(EventExecutor::Create( |
69 input_stub_(new remoting::EventExecutorWin( | |
70 context->main_message_loop(), capturer)), | 52 context->main_message_loop(), capturer)), |
71 #elif defined(OS_LINUX) | |
72 input_stub_(new remoting::EventExecutorLinux( | |
73 context->main_message_loop(), capturer)), | |
74 #elif defined(OS_MACOSX) | |
75 input_stub_(new remoting::EventExecutorMac( | |
76 context->main_message_loop(), capturer)), | |
77 #endif | |
78 host_stub_(new HostStubFake()), | 53 host_stub_(new HostStubFake()), |
79 state_(kInitial) { | 54 state_(kInitial), |
55 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()) { | |
80 } | 56 } |
81 | 57 |
58 | |
82 ChromotingHost::~ChromotingHost() { | 59 ChromotingHost::~ChromotingHost() { |
83 } | 60 } |
84 | 61 |
85 void ChromotingHost::Start(Task* shutdown_task) { | 62 void ChromotingHost::Start(Task* shutdown_task) { |
86 if (MessageLoop::current() != context_->main_message_loop()) { | 63 if (MessageLoop::current() != context_->main_message_loop()) { |
dmac
2010/11/23 01:14:57
DCHECK that protocol_config_ is set?
Sergey Ulanov
2010/11/23 01:59:18
I've added DCHECK in set_protocol_config(). This g
| |
87 context_->main_message_loop()->PostTask( | 64 context_->main_message_loop()->PostTask( |
88 FROM_HERE, | 65 FROM_HERE, |
89 NewRunnableMethod(this, &ChromotingHost::Start, shutdown_task)); | 66 NewRunnableMethod(this, &ChromotingHost::Start, shutdown_task)); |
90 return; | 67 return; |
91 } | 68 } |
92 | 69 |
93 DCHECK(!jingle_client_); | 70 DCHECK(!jingle_client_); |
94 DCHECK(shutdown_task); | 71 DCHECK(shutdown_task); |
95 | 72 |
96 // Make sure this object is not started. | 73 // Make sure this object is not started. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 *response = protocol::SessionManager::DECLINE; | 263 *response = protocol::SessionManager::DECLINE; |
287 return; | 264 return; |
288 } | 265 } |
289 | 266 |
290 // Check that the user has access to the host. | 267 // Check that the user has access to the host. |
291 if (!access_verifier_.VerifyPermissions(session->jid())) { | 268 if (!access_verifier_.VerifyPermissions(session->jid())) { |
292 *response = protocol::SessionManager::DECLINE; | 269 *response = protocol::SessionManager::DECLINE; |
293 return; | 270 return; |
294 } | 271 } |
295 | 272 |
296 scoped_ptr<protocol::CandidateSessionConfig> | 273 *protocol_config_->mutable_initial_resolution() = |
297 local_config(protocol::CandidateSessionConfig::CreateDefault()); | 274 protocol::ScreenResolution(capturer_->width(), capturer_->height()); |
298 local_config->SetInitialResolution( | |
299 protocol::ScreenResolution(capturer_->width(), capturer_->height())); | |
300 // TODO(sergeyu): Respect resolution requested by the client if supported. | 275 // TODO(sergeyu): Respect resolution requested by the client if supported. |
301 protocol::SessionConfig* config = local_config->Select( | 276 protocol::SessionConfig* config = protocol_config_->Select( |
302 session->candidate_config(), true /* force_host_resolution */); | 277 session->candidate_config(), true /* force_host_resolution */); |
303 | 278 |
304 if (!config) { | 279 if (!config) { |
305 LOG(WARNING) << "Rejecting connection from " << session->jid() | 280 LOG(WARNING) << "Rejecting connection from " << session->jid() |
306 << " because no compatible configuration has been found."; | 281 << " because no compatible configuration has been found."; |
307 *response = protocol::SessionManager::INCOMPATIBLE; | 282 *response = protocol::SessionManager::INCOMPATIBLE; |
308 return; | 283 return; |
309 } | 284 } |
310 | 285 |
311 session->set_config(config); | 286 session->set_config(config); |
312 | 287 |
313 *response = protocol::SessionManager::ACCEPT; | 288 *response = protocol::SessionManager::ACCEPT; |
314 | 289 |
315 VLOG(1) << "Client connected: " << session->jid(); | 290 VLOG(1) << "Client connected: " << session->jid(); |
316 | 291 |
317 // If we accept the connected then create a client object and set the | 292 // If we accept the connected then create a client object and set the |
318 // callback. | 293 // callback. |
319 connection_ = new ConnectionToClient(context_->main_message_loop(), | 294 connection_ = new ConnectionToClient(context_->main_message_loop(), |
320 this, host_stub_.get(), | 295 this, host_stub_.get(), |
321 input_stub_.get()); | 296 input_stub_.get()); |
322 connection_->Init(session); | 297 connection_->Init(session); |
323 } | 298 } |
324 | 299 |
300 void ChromotingHost::set_protocol_config( | |
301 protocol::CandidateSessionConfig* config) { | |
302 DCHECK_EQ(state_, kInitial); | |
303 protocol_config_.reset(config); | |
304 } | |
305 | |
325 void ChromotingHost::OnServerClosed() { | 306 void ChromotingHost::OnServerClosed() { |
326 // Don't need to do anything here. | 307 // Don't need to do anything here. |
327 } | 308 } |
328 | 309 |
329 // TODO(sergeyu): Move this to SessionManager? | 310 // TODO(sergeyu): Move this to SessionManager? |
330 Encoder* ChromotingHost::CreateEncoder(const protocol::SessionConfig* config) { | 311 Encoder* ChromotingHost::CreateEncoder(const protocol::SessionConfig* config) { |
331 const protocol::ChannelConfig& video_config = config->video_config(); | 312 const protocol::ChannelConfig& video_config = config->video_config(); |
332 | 313 |
333 if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) { | 314 if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) { |
334 return new remoting::EncoderVerbatim(); | 315 return new remoting::EncoderVerbatim(); |
335 } else if (video_config.codec == protocol::ChannelConfig::CODEC_ZIP) { | 316 } else if (video_config.codec == protocol::ChannelConfig::CODEC_ZIP) { |
336 return new remoting::EncoderZlib(); | 317 return new remoting::EncoderZlib(); |
337 } | 318 } |
338 // TODO(sergeyu): Enable VP8 on ARM builds. | 319 // TODO(sergeyu): Enable VP8 on ARM builds. |
339 #if !defined(ARCH_CPU_ARM_FAMILY) | 320 #if !defined(ARCH_CPU_ARM_FAMILY) |
340 else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) { | 321 else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) { |
341 return new remoting::EncoderVp8(); | 322 return new remoting::EncoderVp8(); |
342 } | 323 } |
343 #endif | 324 #endif |
344 | 325 |
345 return NULL; | 326 return NULL; |
346 } | 327 } |
347 | 328 |
348 } // namespace remoting | 329 } // namespace remoting |
OLD | NEW |