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 18 matching lines...) Loading... | |
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 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
39 #include "remoting/host/capturer_gdi.h" | |
40 #include "remoting/host/event_executor_win.h" | |
41 #elif defined(OS_LINUX) | |
42 #include "remoting/host/capturer_linux.h" | |
43 #include "remoting/host/event_executor_linux.h" | |
44 #elif defined(OS_MACOSX) | |
45 #include "remoting/host/capturer_mac.h" | |
46 #include "remoting/host/event_executor_mac.h" | |
47 #endif | |
48 | |
49 #if defined(OS_WIN) | |
50 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; | 39 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; |
51 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; | 40 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; |
52 const wchar_t kHomePath[] = L"HOMEPATH"; | 41 const wchar_t kHomePath[] = L"HOMEPATH"; |
53 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } | 42 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } |
54 #else | 43 #else |
55 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; | 44 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; |
56 static char* GetEnvironmentVar(const char* x) { return getenv(x); } | 45 static char* GetEnvironmentVar(const char* x) { return getenv(x); } |
57 #endif | 46 #endif |
58 | 47 |
59 void ShutdownTask(MessageLoop* message_loop) { | 48 void ShutdownTask(MessageLoop* message_loop) { |
(...skipping 10 matching lines...) Loading... | |
70 CommandLine::Init(argc, argv); | 59 CommandLine::Init(argc, argv); |
71 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 60 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
72 | 61 |
73 base::AtExitManager exit_manager; | 62 base::AtExitManager exit_manager; |
74 base::EnsureNSPRInit(); | 63 base::EnsureNSPRInit(); |
75 | 64 |
76 // Allocate a chromoting context and starts it. | 65 // Allocate a chromoting context and starts it. |
77 remoting::ChromotingHostContext context; | 66 remoting::ChromotingHostContext context; |
78 context.Start(); | 67 context.Start(); |
79 | 68 |
80 scoped_ptr<remoting::Capturer> capturer; | |
81 scoped_ptr<remoting::protocol::InputStub> input_stub; | |
82 #if defined(OS_WIN) | |
83 capturer.reset(new remoting::CapturerGdi( | |
84 context.capture_message_loop())); | |
85 input_stub.reset(new remoting::EventExecutorWin( | |
86 context.capture_message_loop(), capturer.get())); | |
87 #elif defined(OS_LINUX) | |
88 capturer.reset(new remoting::CapturerLinux( | |
89 context.capture_message_loop())); | |
90 input_stub.reset(new remoting::EventExecutorLinux( | |
91 context.capture_message_loop(), capturer.get())); | |
92 #elif defined(OS_MACOSX) | |
93 capturer.reset(new remoting::CapturerMac( | |
94 context.capture_message_loop())); | |
95 input_stub.reset(new remoting::EventExecutorMac( | |
96 context.capture_message_loop(), capturer.get())); | |
97 #endif | |
98 | |
99 // Check the argument to see if we should use a fake capturer. | |
100 bool fake = cmd_line->HasSwitch(kFakeSwitchName); | |
101 | 69 |
102 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
103 std::wstring home_path = GetEnvironmentVar(kHomeDrive); | 71 std::wstring home_path = GetEnvironmentVar(kHomeDrive); |
104 home_path += GetEnvironmentVar(kHomePath); | 72 home_path += GetEnvironmentVar(kHomePath); |
105 #else | 73 #else |
106 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); | 74 std::string home_path = GetEnvironmentVar(base::env_vars::kHome); |
107 #endif | 75 #endif |
108 FilePath config_path(home_path); | 76 FilePath config_path(home_path); |
109 config_path = config_path.Append(kDefaultConfigPath); | 77 config_path = config_path.Append(kDefaultConfigPath); |
110 if (cmd_line->HasSwitch(kConfigSwitchName)) { | 78 if (cmd_line->HasSwitch(kConfigSwitchName)) { |
111 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); | 79 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); |
112 } | 80 } |
113 | 81 |
114 if (fake) { | |
115 // Inject a fake capturer. | |
Sergey Ulanov
2010/11/17 03:29:19
Can you please not break fake capturer?
| |
116 LOG(INFO) << "Using a fake capturer."; | |
117 capturer.reset(new remoting::CapturerFake(context.capture_message_loop())); | |
118 } | |
119 | |
120 base::Thread file_io_thread("FileIO"); | 82 base::Thread file_io_thread("FileIO"); |
121 file_io_thread.Start(); | 83 file_io_thread.Start(); |
122 | 84 |
123 scoped_refptr<remoting::JsonHostConfig> config( | 85 scoped_refptr<remoting::JsonHostConfig> config( |
124 new remoting::JsonHostConfig( | 86 new remoting::JsonHostConfig( |
125 config_path, file_io_thread.message_loop_proxy())); | 87 config_path, file_io_thread.message_loop_proxy())); |
126 | 88 |
127 if (!config->Read()) { | 89 if (!config->Read()) { |
128 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 90 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
129 context.Stop(); | 91 context.Stop(); |
130 return 1; | 92 return 1; |
131 } | 93 } |
132 | 94 |
133 FilePath module_path; | 95 FilePath module_path; |
134 PathService::Get(base::DIR_MODULE, &module_path); | 96 PathService::Get(base::DIR_MODULE, &module_path); |
135 CHECK(media::InitializeMediaLibrary(module_path)) | 97 CHECK(media::InitializeMediaLibrary(module_path)) |
136 << "Cannot load media library"; | 98 << "Cannot load media library"; |
137 | 99 |
138 // Construct a chromoting host. | 100 // Construct a chromoting host. |
139 scoped_refptr<remoting::ChromotingHost> host( | 101 scoped_refptr<remoting::ChromotingHost> host( |
140 new remoting::ChromotingHost(&context, | 102 new remoting::ChromotingHost(&context, config)); |
141 config, | |
142 capturer.release(), | |
143 input_stub.release())); | |
144 | 103 |
145 // Let the chromoting host run until the shutdown task is executed. | 104 // Let the chromoting host run until the shutdown task is executed. |
146 MessageLoop message_loop(MessageLoop::TYPE_UI); | 105 MessageLoop message_loop(MessageLoop::TYPE_UI); |
147 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); | 106 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
148 message_loop.Run(); | 107 message_loop.Run(); |
149 | 108 |
150 // And then stop the chromoting context. | 109 // And then stop the chromoting context. |
151 context.Stop(); | 110 context.Stop(); |
152 file_io_thread.Stop(); | 111 file_io_thread.Stop(); |
153 return 0; | 112 return 0; |
154 } | 113 } |
OLD | NEW |