Chromium Code Reviews| 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_DESKTOP_SESSION_AGENT_H_ | 5 #ifndef REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
| 6 #define REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 6 #define REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_platform_file.h" | 17 #include "ipc/ipc_platform_file.h" |
| 18 #include "media/video/capture/screen/screen_capturer.h" | 18 #include "media/video/capture/screen/screen_capturer.h" |
| 19 #include "media/video/capture/screen/shared_buffer.h" | |
| 20 #include "remoting/host/client_session_control.h" | 19 #include "remoting/host/client_session_control.h" |
| 21 #include "remoting/protocol/clipboard_stub.h" | 20 #include "remoting/protocol/clipboard_stub.h" |
| 22 #include "third_party/skia/include/core/SkRect.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 23 #include "third_party/skia/include/core/SkSize.h" | |
| 24 | 22 |
| 25 namespace IPC { | 23 namespace IPC { |
| 26 class ChannelProxy; | 24 class ChannelProxy; |
| 27 class Message; | 25 class Message; |
| 28 } // namespace IPC | 26 } // namespace IPC |
| 29 | 27 |
| 30 namespace remoting { | 28 namespace remoting { |
| 31 | 29 |
| 32 class AudioCapturer; | 30 class AudioCapturer; |
| 33 class AudioPacket; | 31 class AudioPacket; |
| 34 class AutoThreadTaskRunner; | 32 class AutoThreadTaskRunner; |
| 35 class DesktopEnvironment; | 33 class DesktopEnvironment; |
| 36 class DesktopEnvironmentFactory; | 34 class DesktopEnvironmentFactory; |
| 37 class InputInjector; | 35 class InputInjector; |
| 38 class RemoteInputFilter; | 36 class RemoteInputFilter; |
| 39 class ScreenControls; | 37 class ScreenControls; |
| 40 class ScreenResolution; | 38 class ScreenResolution; |
| 41 | 39 |
| 42 namespace protocol { | 40 namespace protocol { |
| 43 class InputEventTracker; | 41 class InputEventTracker; |
| 44 } // namespace protocol | 42 } // namespace protocol |
| 45 | 43 |
| 46 // Provides screen/audio capturing and input injection services for | 44 // Provides screen/audio capturing and input injection services for |
| 47 // the network process. | 45 // the network process. |
| 48 class DesktopSessionAgent | 46 class DesktopSessionAgent |
| 49 : public base::RefCountedThreadSafe<DesktopSessionAgent>, | 47 : public base::RefCountedThreadSafe<DesktopSessionAgent>, |
| 50 public IPC::Listener, | 48 public IPC::Listener, |
| 51 public media::ScreenCapturer::Delegate, | 49 public webrtc::DesktopCapturer::Callback, |
| 50 public media::ScreenCapturer::MouseShapeObserver, | |
| 52 public ClientSessionControl { | 51 public ClientSessionControl { |
| 53 public: | 52 public: |
| 54 class Delegate { | 53 class Delegate { |
| 55 public: | 54 public: |
| 56 virtual ~Delegate(); | 55 virtual ~Delegate(); |
| 57 | 56 |
| 58 // Returns an instance of desktop environment factory used. | 57 // Returns an instance of desktop environment factory used. |
| 59 virtual DesktopEnvironmentFactory& desktop_environment_factory() = 0; | 58 virtual DesktopEnvironmentFactory& desktop_environment_factory() = 0; |
| 60 | 59 |
| 61 // Notifies the delegate that the network-to-desktop channel has been | 60 // Notifies the delegate that the network-to-desktop channel has been |
| 62 // disconnected. | 61 // disconnected. |
| 63 virtual void OnNetworkProcessDisconnected() = 0; | 62 virtual void OnNetworkProcessDisconnected() = 0; |
| 64 }; | 63 }; |
| 65 | 64 |
| 66 static scoped_refptr<DesktopSessionAgent> Create( | 65 static scoped_refptr<DesktopSessionAgent> Create( |
| 67 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 66 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 68 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 67 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 69 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 68 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 70 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 69 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 71 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); | 70 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); |
| 72 | 71 |
| 73 // IPC::Listener implementation. | 72 // IPC::Listener implementation. |
| 74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 73 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 75 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 74 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 76 virtual void OnChannelError() OVERRIDE; | 75 virtual void OnChannelError() OVERRIDE; |
| 77 | 76 |
| 78 // media::ScreenCapturer::Delegate implementation. | 77 // webrtc::DesktopCapturer::Callback implementation. |
| 79 virtual scoped_refptr<media::SharedBuffer> CreateSharedBuffer( | 78 virtual webrtc::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; |
| 80 uint32 size) OVERRIDE; | 79 virtual void OnCaptureCompleted(webrtc::DesktopFrame* frame) OVERRIDE; |
| 81 virtual void ReleaseSharedBuffer( | 80 |
| 82 scoped_refptr<media::SharedBuffer> buffer) OVERRIDE; | 81 // media::ScreenCapturer::MouseShapeObserver implementation. |
| 83 virtual void OnCaptureCompleted( | |
| 84 scoped_refptr<media::ScreenCaptureData> capture_data) OVERRIDE; | |
| 85 virtual void OnCursorShapeChanged( | 82 virtual void OnCursorShapeChanged( |
| 86 scoped_ptr<media::MouseCursorShape> cursor_shape) OVERRIDE; | 83 scoped_ptr<media::MouseCursorShape> cursor_shape) OVERRIDE; |
| 87 | 84 |
| 88 // Forwards a local clipboard event though the IPC channel to the network | 85 // Forwards a local clipboard event though the IPC channel to the network |
| 89 // process. | 86 // process. |
| 90 void InjectClipboardEvent(const protocol::ClipboardEvent& event); | 87 void InjectClipboardEvent(const protocol::ClipboardEvent& event); |
| 91 | 88 |
| 92 // Forwards an audio packet though the IPC channel to the network process. | 89 // Forwards an audio packet though the IPC channel to the network process. |
| 93 void ProcessAudioPacket(scoped_ptr<AudioPacket> packet); | 90 void ProcessAudioPacket(scoped_ptr<AudioPacket> packet); |
| 94 | 91 |
| 95 // Creates desktop integration components and a connected IPC channel to be | 92 // Creates desktop integration components and a connected IPC channel to be |
| 96 // used to access them. The client end of the channel is returned in | 93 // used to access them. The client end of the channel is returned in |
| 97 // the variable pointed by |desktop_pipe_out|. | 94 // the variable pointed by |desktop_pipe_out|. |
| 98 bool Start(const base::WeakPtr<Delegate>& delegate, | 95 bool Start(const base::WeakPtr<Delegate>& delegate, |
| 99 IPC::PlatformFileForTransit* desktop_pipe_out); | 96 IPC::PlatformFileForTransit* desktop_pipe_out); |
| 100 | 97 |
| 101 // Stops the agent asynchronously. | 98 // Stops the agent asynchronously. |
| 102 void Stop(); | 99 void Stop(); |
| 103 | 100 |
| 104 protected: | 101 protected: |
| 102 friend class base::RefCountedThreadSafe<DesktopSessionAgent>; | |
| 103 | |
| 105 DesktopSessionAgent( | 104 DesktopSessionAgent( |
| 106 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 105 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 107 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 106 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 108 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 107 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 109 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 108 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 110 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); | 109 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); |
| 111 | |
| 112 friend class base::RefCountedThreadSafe<DesktopSessionAgent>; | |
| 113 virtual ~DesktopSessionAgent(); | 110 virtual ~DesktopSessionAgent(); |
| 114 | 111 |
| 115 // ClientSessionControl interface. | 112 // ClientSessionControl interface. |
| 116 virtual const std::string& client_jid() const OVERRIDE; | 113 virtual const std::string& client_jid() const OVERRIDE; |
| 117 virtual void DisconnectSession() OVERRIDE; | 114 virtual void DisconnectSession() OVERRIDE; |
| 118 virtual void OnLocalMouseMoved(const SkIPoint& position) OVERRIDE; | 115 virtual void OnLocalMouseMoved(const SkIPoint& position) OVERRIDE; |
| 119 virtual void SetDisableInputs(bool disable_inputs) OVERRIDE; | 116 virtual void SetDisableInputs(bool disable_inputs) OVERRIDE; |
| 120 | 117 |
| 121 // Creates a connected IPC channel to be used to access the screen/audio | 118 // Creates a connected IPC channel to be used to access the screen/audio |
| 122 // recorders and input stubs. | 119 // recorders and input stubs. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 175 |
| 179 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { | 176 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { |
| 180 return video_capture_task_runner_; | 177 return video_capture_task_runner_; |
| 181 } | 178 } |
| 182 | 179 |
| 183 const base::WeakPtr<Delegate>& delegate() const { | 180 const base::WeakPtr<Delegate>& delegate() const { |
| 184 return delegate_; | 181 return delegate_; |
| 185 } | 182 } |
| 186 | 183 |
| 187 private: | 184 private: |
| 185 class SharedBuffer; | |
| 186 friend class SharedBuffer; | |
| 187 | |
| 188 // Called by SharedBuffer when it's destroyed. | |
| 189 void OnSharedBufferDeleted(int id); | |
| 190 | |
| 188 // Closes |desktop_pipe_| if it is open. | 191 // Closes |desktop_pipe_| if it is open. |
| 189 void CloseDesktopPipeHandle(); | 192 void CloseDesktopPipeHandle(); |
| 190 | 193 |
| 191 // Task runner dedicated to running methods of |audio_capturer_|. | 194 // Task runner dedicated to running methods of |audio_capturer_|. |
| 192 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner_; | 195 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner_; |
| 193 | 196 |
| 194 // Task runner on which public methods of this class should be called. | 197 // Task runner on which public methods of this class should be called. |
| 195 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; | 198 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; |
| 196 | 199 |
| 197 // Task runner on which keyboard/mouse input is injected. | 200 // Task runner on which keyboard/mouse input is injected. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 scoped_ptr<ScreenControls> screen_controls_; | 232 scoped_ptr<ScreenControls> screen_controls_; |
| 230 | 233 |
| 231 // IPC channel connecting the desktop process with the network process. | 234 // IPC channel connecting the desktop process with the network process. |
| 232 scoped_ptr<IPC::ChannelProxy> network_channel_; | 235 scoped_ptr<IPC::ChannelProxy> network_channel_; |
| 233 | 236 |
| 234 // The client end of the network-to-desktop pipe. It is kept alive until | 237 // The client end of the network-to-desktop pipe. It is kept alive until |
| 235 // the network process connects to the pipe. | 238 // the network process connects to the pipe. |
| 236 IPC::PlatformFileForTransit desktop_pipe_; | 239 IPC::PlatformFileForTransit desktop_pipe_; |
| 237 | 240 |
| 238 // Size of the most recent captured video frame. | 241 // Size of the most recent captured video frame. |
| 239 SkISize current_size_; | 242 webrtc::DesktopSize current_size_; |
| 240 | 243 |
| 241 // Next shared buffer ID to be used. | 244 // Next shared buffer ID to be used. |
| 242 int next_shared_buffer_id_; | 245 int next_shared_buffer_id_; |
| 243 | 246 |
| 244 // List of the shared buffers. | 247 // Number of currently allocated shared buffers. |
|
alexeypa (please no reviews)
2013/05/08 22:24:59
nit: The number
Sergey Ulanov
2013/05/09 18:49:02
Done.
| |
| 245 typedef std::list<scoped_refptr<media::SharedBuffer> > SharedBuffers; | 248 int shared_buffers_; |
| 246 SharedBuffers shared_buffers_; | |
| 247 | 249 |
| 248 // True if the desktop session agent has been started. | 250 // True if the desktop session agent has been started. |
| 249 bool started_; | 251 bool started_; |
| 250 | 252 |
| 251 // Captures the screen. | 253 // Captures the screen. |
| 252 scoped_ptr<media::ScreenCapturer> video_capturer_; | 254 scoped_ptr<media::ScreenCapturer> video_capturer_; |
| 253 | 255 |
| 256 // Keep reference to the last frame sent to make sure shared buffer is alive | |
| 257 // before it's received. | |
| 258 scoped_ptr<webrtc::DesktopFrame> last_frame_; | |
| 259 | |
| 254 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); | 260 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); |
| 255 }; | 261 }; |
| 256 | 262 |
| 257 } // namespace remoting | 263 } // namespace remoting |
| 258 | 264 |
| 259 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 265 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
| OLD | NEW |