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