| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 176 |
| 180 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { | 177 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { |
| 181 return video_capture_task_runner_; | 178 return video_capture_task_runner_; |
| 182 } | 179 } |
| 183 | 180 |
| 184 const base::WeakPtr<Delegate>& delegate() const { | 181 const base::WeakPtr<Delegate>& delegate() const { |
| 185 return delegate_; | 182 return delegate_; |
| 186 } | 183 } |
| 187 | 184 |
| 188 private: | 185 private: |
| 186 class SharedBuffer; |
| 187 friend class SharedBuffer; |
| 188 |
| 189 // Called by SharedBuffer when it's destroyed. |
| 190 void OnSharedBufferDeleted(int id); |
| 191 |
| 189 // Closes |desktop_pipe_| if it is open. | 192 // Closes |desktop_pipe_| if it is open. |
| 190 void CloseDesktopPipeHandle(); | 193 void CloseDesktopPipeHandle(); |
| 191 | 194 |
| 192 // Task runner dedicated to running methods of |audio_capturer_|. | 195 // Task runner dedicated to running methods of |audio_capturer_|. |
| 193 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner_; | 196 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner_; |
| 194 | 197 |
| 195 // Task runner on which public methods of this class should be called. | 198 // Task runner on which public methods of this class should be called. |
| 196 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; | 199 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; |
| 197 | 200 |
| 198 // Task runner on which keyboard/mouse input is injected. | 201 // Task runner on which keyboard/mouse input is injected. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 scoped_ptr<ScreenControls> screen_controls_; | 233 scoped_ptr<ScreenControls> screen_controls_; |
| 231 | 234 |
| 232 // IPC channel connecting the desktop process with the network process. | 235 // IPC channel connecting the desktop process with the network process. |
| 233 scoped_ptr<IPC::ChannelProxy> network_channel_; | 236 scoped_ptr<IPC::ChannelProxy> network_channel_; |
| 234 | 237 |
| 235 // The client end of the network-to-desktop pipe. It is kept alive until | 238 // The client end of the network-to-desktop pipe. It is kept alive until |
| 236 // the network process connects to the pipe. | 239 // the network process connects to the pipe. |
| 237 IPC::PlatformFileForTransit desktop_pipe_; | 240 IPC::PlatformFileForTransit desktop_pipe_; |
| 238 | 241 |
| 239 // Size of the most recent captured video frame. | 242 // Size of the most recent captured video frame. |
| 240 SkISize current_size_; | 243 webrtc::DesktopSize current_size_; |
| 241 | 244 |
| 242 // Next shared buffer ID to be used. | 245 // Next shared buffer ID to be used. |
| 243 int next_shared_buffer_id_; | 246 int next_shared_buffer_id_; |
| 244 | 247 |
| 245 // List of the shared buffers. | 248 // The number of currently allocated shared buffers. |
| 246 typedef std::list<scoped_refptr<media::SharedBuffer> > SharedBuffers; | 249 int shared_buffers_; |
| 247 SharedBuffers shared_buffers_; | |
| 248 | 250 |
| 249 // True if the desktop session agent has been started. | 251 // True if the desktop session agent has been started. |
| 250 bool started_; | 252 bool started_; |
| 251 | 253 |
| 252 // Captures the screen. | 254 // Captures the screen. |
| 253 scoped_ptr<media::ScreenCapturer> video_capturer_; | 255 scoped_ptr<media::ScreenCapturer> video_capturer_; |
| 254 | 256 |
| 257 // Keep reference to the last frame sent to make sure shared buffer is alive |
| 258 // before it's received. |
| 259 scoped_ptr<webrtc::DesktopFrame> last_frame_; |
| 260 |
| 255 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); | 261 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); |
| 256 }; | 262 }; |
| 257 | 263 |
| 258 } // namespace remoting | 264 } // namespace remoting |
| 259 | 265 |
| 260 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 266 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
| OLD | NEW |