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 // This is an application of a minimal host process in a Chromoting | 5 // This is an application of a minimal host process in a Chromoting |
6 // system. It serves the purpose of gluing different pieces together | 6 // system. It serves the purpose of gluing different pieces together |
7 // to make a functional host process for testing. | 7 // to make a functional host process for testing. |
8 // | 8 // |
9 // It peforms the following functionality: | 9 // It peforms the following functionality: |
10 // 1. Connect to the GTalk network and register the machine as a host. | 10 // 1. Connect to the GTalk network and register the machine as a host. |
11 // 2. Accepts connection through libjingle. | 11 // 2. Accepts connection through libjingle. |
12 // 3. Receive mouse / keyboard events through libjingle. | 12 // 3. Receive mouse / keyboard events through libjingle. |
13 // 4. Sends screen capture through libjingle. | 13 // 4. Sends screen capture through libjingle. |
14 | 14 |
15 #include <iostream> | 15 #include <iostream> |
16 #include <string> | 16 #include <string> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 | 18 |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 | 20 |
21 #include "base/at_exit.h" | 21 #include "base/at_exit.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/environment.h" | 23 #include "base/environment.h" |
24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/nss_util.h" | 26 #include "base/nss_util.h" |
27 #include "base/scoped_nsautorelease_pool.h" | 27 #include "base/scoped_nsautorelease_pool.h" |
28 #include "base/thread.h" | 28 #include "base/thread.h" |
| 29 #include "remoting/base/encoder_verbatim.h" |
29 #include "remoting/base/encoder_zlib.h" | 30 #include "remoting/base/encoder_zlib.h" |
30 #include "remoting/host/capturer_fake.h" | 31 #include "remoting/host/capturer_fake.h" |
31 #include "remoting/host/chromoting_host.h" | 32 #include "remoting/host/chromoting_host.h" |
32 #include "remoting/host/chromoting_host_context.h" | 33 #include "remoting/host/chromoting_host_context.h" |
33 #include "remoting/host/json_host_config.h" | 34 #include "remoting/host/json_host_config.h" |
34 | 35 |
35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
36 #include "remoting/host/capturer_gdi.h" | 37 #include "remoting/host/capturer_gdi.h" |
37 #include "remoting/host/event_executor_win.h" | 38 #include "remoting/host/event_executor_win.h" |
38 #elif defined(OS_LINUX) | 39 #elif defined(OS_LINUX) |
(...skipping 13 matching lines...) Expand all Loading... |
52 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; | 53 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; |
53 static char* GetEnvironmentVar(const char* x) { return getenv(x); } | 54 static char* GetEnvironmentVar(const char* x) { return getenv(x); } |
54 #endif | 55 #endif |
55 | 56 |
56 void ShutdownTask(MessageLoop* message_loop) { | 57 void ShutdownTask(MessageLoop* message_loop) { |
57 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 58 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
58 } | 59 } |
59 | 60 |
60 const std::string kFakeSwitchName = "fake"; | 61 const std::string kFakeSwitchName = "fake"; |
61 const std::string kConfigSwitchName = "config"; | 62 const std::string kConfigSwitchName = "config"; |
| 63 const std::string kVerbatimSwitchName = "verbatim"; |
62 | 64 |
63 int main(int argc, char** argv) { | 65 int main(int argc, char** argv) { |
64 // Needed for the Mac, so we don't leak objects when threads are created. | 66 // Needed for the Mac, so we don't leak objects when threads are created. |
65 base::ScopedNSAutoreleasePool pool; | 67 base::ScopedNSAutoreleasePool pool; |
66 | 68 |
67 CommandLine::Init(argc, argv); | 69 CommandLine::Init(argc, argv); |
68 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 70 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
69 | 71 |
70 base::AtExitManager exit_manager; | 72 base::AtExitManager exit_manager; |
71 | 73 |
72 base::EnsureNSPRInit(); | 74 base::EnsureNSPRInit(); |
73 | 75 |
74 scoped_ptr<remoting::Capturer> capturer; | 76 scoped_ptr<remoting::Capturer> capturer; |
75 scoped_ptr<remoting::Encoder> encoder; | 77 scoped_ptr<remoting::Encoder> encoder; |
76 scoped_ptr<remoting::EventExecutor> executor; | 78 scoped_ptr<remoting::EventExecutor> event_handler; |
77 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
78 capturer.reset(new remoting::CapturerGdi()); | 80 capturer.reset(new remoting::CapturerGdi()); |
79 executor.reset(new remoting::EventExecutorWin()); | 81 event_handler.reset(new remoting::EventExecutorWin(capturer.get())); |
80 #elif defined(OS_LINUX) | 82 #elif defined(OS_LINUX) |
81 capturer.reset(new remoting::CapturerLinux()); | 83 capturer.reset(new remoting::CapturerLinux()); |
82 executor.reset(new remoting::EventExecutorLinux()); | 84 event_handler.reset(new remoting::EventExecutorLinux(capturer.get())); |
83 #elif defined(OS_MACOSX) | 85 #elif defined(OS_MACOSX) |
84 capturer.reset(new remoting::CapturerMac()); | 86 capturer.reset(new remoting::CapturerMac()); |
85 executor.reset(new remoting::EventExecutorMac()); | 87 event_handler.reset(new remoting::EventExecutorMac(capturer.get())); |
86 #endif | 88 #endif |
87 encoder.reset(new remoting::EncoderZlib()); | 89 encoder.reset(new remoting::EncoderZlib()); |
88 | 90 |
89 // Check the argument to see if we should use a fake capturer and encoder. | 91 // Check the argument to see if we should use a fake capturer and encoder. |
90 bool fake = cmd_line->HasSwitch(kFakeSwitchName); | 92 bool fake = cmd_line->HasSwitch(kFakeSwitchName); |
| 93 bool verbatim = cmd_line->HasSwitch(kVerbatimSwitchName); |
91 | 94 |
92 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
93 std::wstring path = GetEnvironmentVar(kHomeDrive); | 96 std::wstring path = GetEnvironmentVar(kHomeDrive); |
94 path += GetEnvironmentVar(kHomePath); | 97 path += GetEnvironmentVar(kHomePath); |
95 #else | 98 #else |
96 std::string path = GetEnvironmentVar(base::env_vars::kHome); | 99 std::string path = GetEnvironmentVar(base::env_vars::kHome); |
97 #endif | 100 #endif |
98 FilePath config_path(path); | 101 FilePath config_path(path); |
99 config_path = config_path.Append(kDefaultConfigPath); | 102 config_path = config_path.Append(kDefaultConfigPath); |
100 if (cmd_line->HasSwitch(kConfigSwitchName)) { | 103 if (cmd_line->HasSwitch(kConfigSwitchName)) { |
101 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); | 104 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); |
102 } | 105 } |
103 | 106 |
104 if (fake) { | 107 if (fake) { |
105 // Inject a fake capturer. | 108 // Inject a fake capturer. |
106 LOG(INFO) << "Using a fake capturer."; | 109 LOG(INFO) << "Using a fake capturer."; |
107 capturer.reset(new remoting::CapturerFake()); | 110 capturer.reset(new remoting::CapturerFake()); |
108 } | 111 } |
109 | 112 |
| 113 if (verbatim) { |
| 114 LOG(INFO) << "Using the verbatim encoder."; |
| 115 encoder.reset(new remoting::EncoderVerbatim()); |
| 116 } |
| 117 |
110 base::Thread file_io_thread("FileIO"); | 118 base::Thread file_io_thread("FileIO"); |
111 file_io_thread.Start(); | 119 file_io_thread.Start(); |
112 | 120 |
113 scoped_refptr<remoting::JsonHostConfig> config( | 121 scoped_refptr<remoting::JsonHostConfig> config( |
114 new remoting::JsonHostConfig( | 122 new remoting::JsonHostConfig( |
115 config_path, file_io_thread.message_loop_proxy())); | 123 config_path, file_io_thread.message_loop_proxy())); |
116 | 124 |
117 if (!config->Read()) { | 125 if (!config->Read()) { |
118 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 126 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
119 return 1; | 127 return 1; |
120 } | 128 } |
121 | 129 |
122 // Allocate a chromoting context and starts it. | 130 // Allocate a chromoting context and starts it. |
123 remoting::ChromotingHostContext context; | 131 remoting::ChromotingHostContext context; |
124 context.Start(); | 132 context.Start(); |
125 | 133 |
126 // Construct a chromoting host. | 134 // Construct a chromoting host. |
127 scoped_refptr<remoting::ChromotingHost> host = | 135 scoped_refptr<remoting::ChromotingHost> host = |
128 new remoting::ChromotingHost(&context, | 136 new remoting::ChromotingHost(&context, |
129 config, | 137 config, |
130 capturer.release(), | 138 capturer.release(), |
131 encoder.release(), | 139 encoder.release(), |
132 executor.release()); | 140 event_handler.release()); |
133 | 141 |
134 // Let the chromoting host run until the shutdown task is executed. | 142 // Let the chromoting host run until the shutdown task is executed. |
135 MessageLoop message_loop(MessageLoop::TYPE_UI); | 143 MessageLoop message_loop(MessageLoop::TYPE_UI); |
136 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); | 144 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
137 message_loop.Run(); | 145 message_loop.Run(); |
138 | 146 |
139 // And then stop the chromoting context. | 147 // And then stop the chromoting context. |
140 context.Stop(); | 148 context.Stop(); |
141 file_io_thread.Stop(); | 149 file_io_thread.Stop(); |
142 return 0; | 150 return 0; |
143 } | 151 } |
OLD | NEW |