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