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. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "base/path_service.h" | 28 #include "base/path_service.h" |
29 #include "base/thread.h" | 29 #include "base/thread.h" |
30 #include "media/base/media.h" | 30 #include "media/base/media.h" |
31 #include "remoting/base/tracer.h" | 31 #include "remoting/base/tracer.h" |
32 #include "remoting/host/capturer_fake.h" | 32 #include "remoting/host/capturer_fake.h" |
33 #include "remoting/host/chromoting_host.h" | 33 #include "remoting/host/chromoting_host.h" |
34 #include "remoting/host/chromoting_host_context.h" | 34 #include "remoting/host/chromoting_host_context.h" |
35 #include "remoting/host/json_host_config.h" | 35 #include "remoting/host/json_host_config.h" |
36 #include "remoting/proto/video.pb.h" | 36 #include "remoting/proto/video.pb.h" |
37 | 37 |
| 38 using remoting::ChromotingHost; |
| 39 using remoting::protocol::CandidateSessionConfig; |
| 40 using remoting::protocol::ChannelConfig; |
| 41 using std::string; |
| 42 using std::wstring; |
| 43 |
38 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
39 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; | 45 const wchar_t kDefaultConfigPath[] = L".ChromotingConfig.json"; |
40 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; | 46 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; |
41 const wchar_t kHomePath[] = L"HOMEPATH"; | 47 const wchar_t kHomePath[] = L"HOMEPATH"; |
| 48 // TODO(sergeyu): Use environment utils from base/environment.h. |
42 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } | 49 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } |
43 #else | 50 #else |
44 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; | 51 const char kDefaultConfigPath[] = ".ChromotingConfig.json"; |
45 static char* GetEnvironmentVar(const char* x) { return getenv(x); } | 52 static char* GetEnvironmentVar(const char* x) { return getenv(x); } |
46 #endif | 53 #endif |
47 | 54 |
48 void ShutdownTask(MessageLoop* message_loop) { | 55 void ShutdownTask(MessageLoop* message_loop) { |
49 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 56 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
50 } | 57 } |
51 | 58 |
52 const std::string kFakeSwitchName = "fake"; | 59 const char kFakeSwitchName[] = "fake"; |
53 const std::string kConfigSwitchName = "config"; | 60 const char kConfigSwitchName[] = "config"; |
| 61 const char kVideoSwitchName[] = "video"; |
| 62 |
| 63 const char kVideoSwitchValueVerbatim[] = "verbatim"; |
| 64 const char kVideoSwitchValueZip[] = "zip"; |
| 65 const char kVideoSwitchValueVp8[] = "vp8"; |
| 66 const char kVideoSwitchValueVp8Rtp[] = "vp8rtp"; |
| 67 |
54 | 68 |
55 int main(int argc, char** argv) { | 69 int main(int argc, char** argv) { |
56 // Needed for the Mac, so we don't leak objects when threads are created. | 70 // Needed for the Mac, so we don't leak objects when threads are created. |
57 base::mac::ScopedNSAutoreleasePool pool; | 71 base::mac::ScopedNSAutoreleasePool pool; |
58 | 72 |
59 CommandLine::Init(argc, argv); | 73 CommandLine::Init(argc, argv); |
60 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 74 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
61 | 75 |
62 base::AtExitManager exit_manager; | 76 base::AtExitManager exit_manager; |
63 base::EnsureNSPRInit(); | 77 base::EnsureNSPRInit(); |
64 | 78 |
65 // Allocate a chromoting context and starts it. | 79 // Allocate a chromoting context and starts it. |
66 remoting::ChromotingHostContext context; | 80 remoting::ChromotingHostContext context; |
67 context.Start(); | 81 context.Start(); |
68 | 82 |
69 | 83 |
70 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
71 std::wstring home_path = GetEnvironmentVar(kHomeDrive); | 85 wstring home_path = GetEnvironmentVar(kHomeDrive); |
72 home_path += GetEnvironmentVar(kHomePath); | 86 home_path += GetEnvironmentVar(kHomePath); |
73 #else | 87 #else |
74 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); | 88 string home_path = GetEnvironmentVar(base::env_vars::kHome); |
75 #endif | 89 #endif |
76 FilePath config_path(home_path); | 90 FilePath config_path(home_path); |
77 config_path = config_path.Append(kDefaultConfigPath); | 91 config_path = config_path.Append(kDefaultConfigPath); |
78 if (cmd_line->HasSwitch(kConfigSwitchName)) { | 92 if (cmd_line->HasSwitch(kConfigSwitchName)) { |
79 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); | 93 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); |
80 } | 94 } |
81 | 95 |
82 base::Thread file_io_thread("FileIO"); | 96 base::Thread file_io_thread("FileIO"); |
83 file_io_thread.Start(); | 97 file_io_thread.Start(); |
84 | 98 |
85 scoped_refptr<remoting::JsonHostConfig> config( | 99 scoped_refptr<remoting::JsonHostConfig> config( |
86 new remoting::JsonHostConfig( | 100 new remoting::JsonHostConfig( |
87 config_path, file_io_thread.message_loop_proxy())); | 101 config_path, file_io_thread.message_loop_proxy())); |
88 | 102 |
89 if (!config->Read()) { | 103 if (!config->Read()) { |
90 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 104 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
91 context.Stop(); | 105 context.Stop(); |
92 return 1; | 106 return 1; |
93 } | 107 } |
94 | 108 |
95 FilePath module_path; | 109 FilePath module_path; |
96 PathService::Get(base::DIR_MODULE, &module_path); | 110 PathService::Get(base::DIR_MODULE, &module_path); |
97 CHECK(media::InitializeMediaLibrary(module_path)) | 111 CHECK(media::InitializeMediaLibrary(module_path)) |
98 << "Cannot load media library"; | 112 << "Cannot load media library"; |
99 | 113 |
100 // Construct a chromoting host. | 114 // Construct a chromoting host. |
101 scoped_refptr<remoting::ChromotingHost> host; | 115 scoped_refptr<ChromotingHost> host; |
102 | 116 |
103 bool fake = cmd_line->HasSwitch(kFakeSwitchName); | 117 bool fake = cmd_line->HasSwitch(kFakeSwitchName); |
104 if (fake) { | 118 if (fake) { |
105 host = new remoting::ChromotingHost( | 119 host = ChromotingHost::Create( |
106 &context, config, | 120 &context, config, |
107 new remoting::CapturerFake(context.main_message_loop())); | 121 new remoting::CapturerFake(context.main_message_loop())); |
108 } else { | 122 } else { |
109 host = new remoting::ChromotingHost(&context, config); | 123 host = ChromotingHost::Create(&context, config); |
| 124 } |
| 125 |
| 126 if (cmd_line->HasSwitch(kVideoSwitchName)) { |
| 127 string video_codec = cmd_line->GetSwitchValueASCII(kVideoSwitchName); |
| 128 scoped_ptr<CandidateSessionConfig> config( |
| 129 CandidateSessionConfig::CreateDefault()); |
| 130 config->mutable_video_configs()->clear(); |
| 131 |
| 132 ChannelConfig::TransportType transport = ChannelConfig::TRANSPORT_STREAM; |
| 133 ChannelConfig::Codec codec; |
| 134 if (video_codec == kVideoSwitchValueVerbatim) { |
| 135 codec = ChannelConfig::CODEC_VERBATIM; |
| 136 } else if (video_codec == kVideoSwitchValueZip) { |
| 137 codec = ChannelConfig::CODEC_ZIP; |
| 138 } else if (video_codec == kVideoSwitchValueVp8) { |
| 139 codec = ChannelConfig::CODEC_VP8; |
| 140 } else if (video_codec == kVideoSwitchValueVp8Rtp) { |
| 141 transport = ChannelConfig::TRANSPORT_SRTP; |
| 142 codec = ChannelConfig::CODEC_VP8; |
| 143 } else { |
| 144 LOG(ERROR) << "Unknown video codec: " << video_codec; |
| 145 context.Stop(); |
| 146 return 1; |
| 147 } |
| 148 config->mutable_video_configs()->push_back(ChannelConfig( |
| 149 transport, remoting::protocol::kDefaultStreamVersion, codec)); |
| 150 host->set_protocol_config(config.release()); |
110 } | 151 } |
111 | 152 |
112 // Let the chromoting host run until the shutdown task is executed. | 153 // Let the chromoting host run until the shutdown task is executed. |
113 MessageLoop message_loop(MessageLoop::TYPE_UI); | 154 MessageLoop message_loop(MessageLoop::TYPE_UI); |
114 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); | 155 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
115 message_loop.Run(); | 156 message_loop.Run(); |
116 | 157 |
117 // And then stop the chromoting context. | 158 // And then stop the chromoting context. |
118 context.Stop(); | 159 context.Stop(); |
119 file_io_thread.Stop(); | 160 file_io_thread.Stop(); |
120 return 0; | 161 return 0; |
121 } | 162 } |
OLD | NEW |