OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef REMOTING_HOST_CHROMOTING_HOST_H_ | 5 #ifndef REMOTING_HOST_CHROMOTING_HOST_H_ |
6 #define REMOTING_HOST_CHROMOTING_HOST_H_ | 6 #define REMOTING_HOST_CHROMOTING_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "net/base/backoff_entry.h" | 14 #include "net/base/backoff_entry.h" |
| 15 #include "remoting/codec/video_encoder.h" |
15 #include "remoting/host/client_session.h" | 16 #include "remoting/host/client_session.h" |
| 17 #include "remoting/host/desktop_environment.h" |
16 #include "remoting/host/host_key_pair.h" | 18 #include "remoting/host/host_key_pair.h" |
17 #include "remoting/host/host_status_observer.h" | 19 #include "remoting/host/host_status_observer.h" |
18 #include "remoting/host/mouse_move_observer.h" | 20 #include "remoting/host/mouse_move_observer.h" |
19 #include "remoting/host/ui_strings.h" | 21 #include "remoting/host/ui_strings.h" |
20 #include "remoting/protocol/authenticator.h" | 22 #include "remoting/protocol/authenticator.h" |
21 #include "remoting/protocol/session_manager.h" | 23 #include "remoting/protocol/session_manager.h" |
22 #include "remoting/protocol/connection_to_client.h" | 24 #include "remoting/protocol/connection_to_client.h" |
23 | 25 |
24 namespace remoting { | 26 namespace remoting { |
25 | 27 |
26 namespace protocol { | 28 namespace protocol { |
27 class InputStub; | 29 class InputStub; |
28 class SessionConfig; | 30 class SessionConfig; |
29 class CandidateSessionConfig; | 31 class CandidateSessionConfig; |
30 } // namespace protocol | 32 } // namespace protocol |
31 | 33 |
| 34 class AudioEncoder; |
| 35 class AudioScheduler; |
32 class ChromotingHostContext; | 36 class ChromotingHostContext; |
33 class DesktopEnvironmentFactory; | 37 class DesktopEnvironment; |
| 38 class Encoder; |
| 39 class ScreenRecorder; |
| 40 class VideoFrameCapturer; |
34 | 41 |
35 // A class to implement the functionality of a host process. | 42 // A class to implement the functionality of a host process. |
36 // | 43 // |
37 // Here's the work flow of this class: | 44 // Here's the work flow of this class: |
38 // 1. We should load the saved GAIA ID token or if this is the first | 45 // 1. We should load the saved GAIA ID token or if this is the first |
39 // time the host process runs we should prompt user for the | 46 // time the host process runs we should prompt user for the |
40 // credential. We will use this token or credentials to authenicate | 47 // credential. We will use this token or credentials to authenicate |
41 // and register the host. | 48 // and register the host. |
42 // | 49 // |
43 // 2. We listen for incoming connection using libjingle. We will create | 50 // 2. We listen for incoming connection using libjingle. We will create |
(...skipping 11 matching lines...) Expand all Loading... |
55 // all pending tasks to complete. After all of that completed we | 62 // all pending tasks to complete. After all of that completed we |
56 // return to the idle state. We then go to step (2) if there a new | 63 // return to the idle state. We then go to step (2) if there a new |
57 // incoming connection. | 64 // incoming connection. |
58 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, | 65 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, |
59 public ClientSession::EventHandler, | 66 public ClientSession::EventHandler, |
60 public protocol::SessionManager::Listener, | 67 public protocol::SessionManager::Listener, |
61 public MouseMoveObserver { | 68 public MouseMoveObserver { |
62 public: | 69 public: |
63 // The caller must ensure that |context|, |signal_strategy| and | 70 // The caller must ensure that |context|, |signal_strategy| and |
64 // |environment| out-live the host. | 71 // |environment| out-live the host. |
65 ChromotingHost( | 72 ChromotingHost(ChromotingHostContext* context, |
66 ChromotingHostContext* context, | 73 SignalStrategy* signal_strategy, |
67 SignalStrategy* signal_strategy, | 74 DesktopEnvironment* environment, |
68 DesktopEnvironmentFactory* desktop_environment_factory, | 75 scoped_ptr<protocol::SessionManager> session_manager); |
69 scoped_ptr<protocol::SessionManager> session_manager); | |
70 | 76 |
71 // Asynchronously start the host process. | 77 // Asynchronously start the host process. |
72 // | 78 // |
73 // After this is invoked, the host process will connect to the talk | 79 // After this is invoked, the host process will connect to the talk |
74 // network and start listening for incoming connections. | 80 // network and start listening for incoming connections. |
75 // | 81 // |
76 // This method can only be called once during the lifetime of this object. | 82 // This method can only be called once during the lifetime of this object. |
77 void Start(const std::string& xmpp_login); | 83 void Start(const std::string& xmpp_login); |
78 | 84 |
79 // Asynchronously shutdown the host process. |shutdown_task| is | 85 // Asynchronously shutdown the host process. |shutdown_task| is |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 156 |
151 typedef std::vector<ClientSession*> ClientList; | 157 typedef std::vector<ClientSession*> ClientList; |
152 | 158 |
153 enum State { | 159 enum State { |
154 kInitial, | 160 kInitial, |
155 kStarted, | 161 kStarted, |
156 kStopping, | 162 kStopping, |
157 kStopped, | 163 kStopped, |
158 }; | 164 }; |
159 | 165 |
| 166 // Creates encoder for the specified configuration. |
| 167 static VideoEncoder* CreateVideoEncoder( |
| 168 const protocol::SessionConfig& config); |
| 169 |
| 170 // Creates an audio encoder for the specified configuration. |
| 171 static scoped_ptr<AudioEncoder> CreateAudioEncoder( |
| 172 const protocol::SessionConfig& config); |
| 173 |
160 virtual ~ChromotingHost(); | 174 virtual ~ChromotingHost(); |
161 | 175 |
162 // Called when a client session is stopped completely. | 176 void StopScreenRecorder(); |
163 void OnClientStopped(); | 177 void StopAudioScheduler(); |
| 178 void OnRecorderStopped(); |
164 | 179 |
165 // Called from Shutdown() to finish shutdown. | 180 // Called from Shutdown() or OnScreenRecorderStopped() to finish shutdown. |
166 void ShutdownFinish(); | 181 void ShutdownFinish(); |
167 | 182 |
168 // Unless specified otherwise all members of this class must be | 183 // Unless specified otherwise all members of this class must be |
169 // used on the network thread only. | 184 // used on the network thread only. |
170 | 185 |
171 // Parameters specified when the host was created. | 186 // Parameters specified when the host was created. |
172 ChromotingHostContext* context_; | 187 ChromotingHostContext* context_; |
173 DesktopEnvironmentFactory* desktop_environment_factory_; | 188 DesktopEnvironment* desktop_environment_; |
174 scoped_ptr<protocol::SessionManager> session_manager_; | 189 scoped_ptr<protocol::SessionManager> session_manager_; |
175 | 190 |
176 // Connection objects. | 191 // Connection objects. |
177 SignalStrategy* signal_strategy_; | 192 SignalStrategy* signal_strategy_; |
178 | 193 |
179 // Must be used on the network thread only. | 194 // Must be used on the network thread only. |
180 ObserverList<HostStatusObserver> status_observers_; | 195 ObserverList<HostStatusObserver> status_observers_; |
181 | 196 |
182 // The connections to remote clients. | 197 // The connections to remote clients. |
183 ClientList clients_; | 198 ClientList clients_; |
184 | 199 |
185 // The number of allocated |ClientSession| objects. |clients_count_| can be | 200 // Schedulers for audio and video capture. |
186 // greater than |clients_.size()| because it also includes the objects that | 201 // TODO(sergeyu): Do we need to have one set of schedulers per client? |
187 // are about to be deleted. | 202 scoped_refptr<ScreenRecorder> recorder_; |
188 int clients_count_; | 203 scoped_refptr<AudioScheduler> audio_scheduler_; |
| 204 |
| 205 // Number of screen recorders and audio schedulers that are currently being |
| 206 // stopped. Used to delay shutdown if one or more recorders/schedulers are |
| 207 // asynchronously shutting down. |
| 208 int stopping_recorders_; |
189 | 209 |
190 // Tracks the internal state of the host. | 210 // Tracks the internal state of the host. |
191 State state_; | 211 State state_; |
192 | 212 |
193 // Configuration of the protocol. | 213 // Configuration of the protocol. |
194 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; | 214 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; |
195 | 215 |
196 // Login backoff state. | 216 // Login backoff state. |
197 net::BackoffEntry login_backoff_; | 217 net::BackoffEntry login_backoff_; |
198 | 218 |
(...skipping 11 matching lines...) Expand all Loading... |
210 | 230 |
211 // The maximum duration of any session. | 231 // The maximum duration of any session. |
212 base::TimeDelta max_session_duration_; | 232 base::TimeDelta max_session_duration_; |
213 | 233 |
214 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); | 234 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); |
215 }; | 235 }; |
216 | 236 |
217 } // namespace remoting | 237 } // namespace remoting |
218 | 238 |
219 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ | 239 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ |
OLD | NEW |