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/mac/scoped_nsautorelease_pool.h" | 26 #include "base/mac/scoped_nsautorelease_pool.h" |
27 #include "base/nss_util.h" | 27 #include "base/nss_util.h" |
| 28 #include "base/path_service.h" |
28 #include "base/thread.h" | 29 #include "base/thread.h" |
| 30 #include "media/base/media.h" |
29 #include "remoting/base/encoder_verbatim.h" | 31 #include "remoting/base/encoder_verbatim.h" |
| 32 #include "remoting/base/encoder_vp8.h" |
30 #include "remoting/base/encoder_zlib.h" | 33 #include "remoting/base/encoder_zlib.h" |
| 34 #include "remoting/base/tracer.h" |
31 #include "remoting/host/capturer_fake.h" | 35 #include "remoting/host/capturer_fake.h" |
32 #include "remoting/host/chromoting_host.h" | 36 #include "remoting/host/chromoting_host.h" |
33 #include "remoting/host/chromoting_host_context.h" | 37 #include "remoting/host/chromoting_host_context.h" |
34 #include "remoting/host/json_host_config.h" | 38 #include "remoting/host/json_host_config.h" |
35 #include "remoting/base/tracer.h" | 39 #include "remoting/proto/video.pb.h" |
36 | 40 |
37 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
38 #include "remoting/host/capturer_gdi.h" | 42 #include "remoting/host/capturer_gdi.h" |
39 #include "remoting/host/event_executor_win.h" | 43 #include "remoting/host/event_executor_win.h" |
40 #elif defined(OS_LINUX) | 44 #elif defined(OS_LINUX) |
41 #include "remoting/host/capturer_linux.h" | 45 #include "remoting/host/capturer_linux.h" |
42 #include "remoting/host/event_executor_linux.h" | 46 #include "remoting/host/event_executor_linux.h" |
43 #elif defined(OS_MACOSX) | 47 #elif defined(OS_MACOSX) |
44 #include "remoting/host/capturer_mac.h" | 48 #include "remoting/host/capturer_mac.h" |
45 #include "remoting/host/event_executor_mac.h" | 49 #include "remoting/host/event_executor_mac.h" |
46 #endif | 50 #endif |
47 | 51 |
48 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
49 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; | 53 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; |
50 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; | 54 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; |
51 const wchar_t kHomePath[] = L"HOMEPATH"; | 55 const wchar_t kHomePath[] = L"HOMEPATH"; |
52 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } | 56 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } |
53 #else | 57 #else |
54 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; | 58 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; |
55 static char* GetEnvironmentVar(const char* x) { return getenv(x); } | 59 static char* GetEnvironmentVar(const char* x) { return getenv(x); } |
56 #endif | 60 #endif |
57 | 61 |
58 void ShutdownTask(MessageLoop* message_loop) { | 62 void ShutdownTask(MessageLoop* message_loop) { |
59 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 63 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
60 } | 64 } |
61 | 65 |
62 const std::string kFakeSwitchName = "fake"; | 66 const std::string kFakeSwitchName = "fake"; |
63 const std::string kConfigSwitchName = "config"; | 67 const std::string kConfigSwitchName = "config"; |
64 const std::string kVerbatimSwitchName = "verbatim"; | 68 const std::string kVerbatimSwitchName = "verbatim"; |
| 69 const std::string kVp8SwitchName = "vp8"; |
65 | 70 |
66 int main(int argc, char** argv) { | 71 int main(int argc, char** argv) { |
67 // Needed for the Mac, so we don't leak objects when threads are created. | 72 // Needed for the Mac, so we don't leak objects when threads are created. |
68 base::mac::ScopedNSAutoreleasePool pool; | 73 base::mac::ScopedNSAutoreleasePool pool; |
69 | 74 |
70 CommandLine::Init(argc, argv); | 75 CommandLine::Init(argc, argv); |
71 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 76 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
72 | 77 |
73 base::AtExitManager exit_manager; | 78 base::AtExitManager exit_manager; |
74 | 79 |
(...skipping 10 matching lines...) Expand all Loading... |
85 event_handler.reset(new remoting::EventExecutorLinux(capturer.get())); | 90 event_handler.reset(new remoting::EventExecutorLinux(capturer.get())); |
86 #elif defined(OS_MACOSX) | 91 #elif defined(OS_MACOSX) |
87 capturer.reset(new remoting::CapturerMac()); | 92 capturer.reset(new remoting::CapturerMac()); |
88 event_handler.reset(new remoting::EventExecutorMac(capturer.get())); | 93 event_handler.reset(new remoting::EventExecutorMac(capturer.get())); |
89 #endif | 94 #endif |
90 encoder.reset(new remoting::EncoderZlib()); | 95 encoder.reset(new remoting::EncoderZlib()); |
91 | 96 |
92 // Check the argument to see if we should use a fake capturer and encoder. | 97 // Check the argument to see if we should use a fake capturer and encoder. |
93 bool fake = cmd_line->HasSwitch(kFakeSwitchName); | 98 bool fake = cmd_line->HasSwitch(kFakeSwitchName); |
94 bool verbatim = cmd_line->HasSwitch(kVerbatimSwitchName); | 99 bool verbatim = cmd_line->HasSwitch(kVerbatimSwitchName); |
| 100 bool vp8 = cmd_line->HasSwitch(kVp8SwitchName); |
95 | 101 |
96 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
97 std::wstring path = GetEnvironmentVar(kHomeDrive); | 103 std::wstring home_path = GetEnvironmentVar(kHomeDrive); |
98 path += GetEnvironmentVar(kHomePath); | 104 home_path += GetEnvironmentVar(kHomePath); |
99 #else | 105 #else |
100 std::string path = GetEnvironmentVar(base::env_vars::kHome); | 106 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); |
101 #endif | 107 #endif |
102 FilePath config_path(path); | 108 FilePath config_path(home_path); |
103 config_path = config_path.Append(kDefaultConfigPath); | 109 config_path = config_path.Append(kDefaultConfigPath); |
104 if (cmd_line->HasSwitch(kConfigSwitchName)) { | 110 if (cmd_line->HasSwitch(kConfigSwitchName)) { |
105 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); | 111 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); |
106 } | 112 } |
107 | 113 |
108 if (fake) { | 114 if (fake) { |
109 // Inject a fake capturer. | 115 // Inject a fake capturer. |
110 LOG(INFO) << "Using a fake capturer."; | 116 LOG(INFO) << "Using a fake capturer."; |
111 capturer.reset(new remoting::CapturerFake()); | 117 capturer.reset(new remoting::CapturerFake()); |
112 } | 118 } |
113 | 119 |
114 if (verbatim) { | 120 if (verbatim) { |
115 LOG(INFO) << "Using the verbatim encoder."; | 121 LOG(INFO) << "Using the verbatim encoder."; |
116 encoder.reset(new remoting::EncoderVerbatim()); | 122 encoder.reset(new remoting::EncoderVerbatim()); |
117 } | 123 } |
118 | 124 |
| 125 // TODO(sergeyu): Enable VP8 on ARM builds. |
| 126 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 127 if (vp8) { |
| 128 LOG(INFO) << "Using the verbatim encoder."; |
| 129 encoder.reset(new remoting::EncoderVp8()); |
| 130 } |
| 131 #endif |
| 132 |
119 base::Thread file_io_thread("FileIO"); | 133 base::Thread file_io_thread("FileIO"); |
120 file_io_thread.Start(); | 134 file_io_thread.Start(); |
121 | 135 |
122 scoped_refptr<remoting::JsonHostConfig> config( | 136 scoped_refptr<remoting::JsonHostConfig> config( |
123 new remoting::JsonHostConfig( | 137 new remoting::JsonHostConfig( |
124 config_path, file_io_thread.message_loop_proxy())); | 138 config_path, file_io_thread.message_loop_proxy())); |
125 | 139 |
126 if (!config->Read()) { | 140 if (!config->Read()) { |
127 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 141 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
128 return 1; | 142 return 1; |
129 } | 143 } |
130 | 144 |
131 // Allocate a chromoting context and starts it. | 145 // Allocate a chromoting context and starts it. |
132 remoting::ChromotingHostContext context; | 146 remoting::ChromotingHostContext context; |
133 context.Start(); | 147 context.Start(); |
134 | 148 |
| 149 FilePath module_path; |
| 150 PathService::Get(base::DIR_MODULE, &module_path); |
| 151 CHECK(media::InitializeMediaLibrary(module_path)) |
| 152 << "Cannot load media library"; |
| 153 |
135 // Construct a chromoting host. | 154 // Construct a chromoting host. |
136 scoped_refptr<remoting::ChromotingHost> host( | 155 scoped_refptr<remoting::ChromotingHost> host( |
137 new remoting::ChromotingHost(&context, | 156 new remoting::ChromotingHost(&context, |
138 config, | 157 config, |
139 capturer.release(), | 158 capturer.release(), |
140 encoder.release(), | 159 encoder.release(), |
141 event_handler.release())); | 160 event_handler.release())); |
142 | 161 |
143 // Let the chromoting host run until the shutdown task is executed. | 162 // Let the chromoting host run until the shutdown task is executed. |
144 MessageLoop message_loop(MessageLoop::TYPE_UI); | 163 MessageLoop message_loop(MessageLoop::TYPE_UI); |
145 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); | 164 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
146 message_loop.Run(); | 165 message_loop.Run(); |
147 | 166 |
148 // And then stop the chromoting context. | 167 // And then stop the chromoting context. |
149 context.Stop(); | 168 context.Stop(); |
150 file_io_thread.Stop(); | 169 file_io_thread.Stop(); |
151 return 0; | 170 return 0; |
152 } | 171 } |
OLD | NEW |