| 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_PROXY_H_ | 5 #ifndef REMOTING_HOST_DESKTOP_SESSION_PROXY_H_ |
| 6 #define REMOTING_HOST_DESKTOP_SESSION_PROXY_H_ | 6 #define REMOTING_HOST_DESKTOP_SESSION_PROXY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "ipc/ipc_listener.h" | 14 #include "ipc/ipc_listener.h" |
| 15 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
| 16 #include "remoting/capturer/shared_buffer.h" | 16 #include "remoting/capturer/shared_buffer.h" |
| 17 #include "remoting/capturer/video_frame_capturer.h" | 17 #include "remoting/capturer/video_frame_capturer.h" |
| 18 #include "remoting/host/audio_capturer.h" |
| 19 #include "remoting/host/desktop_environment.h" |
| 18 #include "remoting/proto/event.pb.h" | 20 #include "remoting/proto/event.pb.h" |
| 19 #include "remoting/protocol/clipboard_stub.h" | 21 #include "remoting/protocol/clipboard_stub.h" |
| 20 #include "third_party/skia/include/core/SkRegion.h" | 22 #include "third_party/skia/include/core/SkRegion.h" |
| 21 | 23 |
| 22 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 23 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 28 } // namespace base | 30 } // namespace base |
| 29 | 31 |
| 30 namespace IPC { | 32 namespace IPC { |
| 31 class ChannelProxy; | 33 class ChannelProxy; |
| 32 class Message; | 34 class Message; |
| 33 } // namespace IPC | 35 } // namespace IPC |
| 34 | 36 |
| 35 struct SerializedCapturedData; | 37 struct SerializedCapturedData; |
| 36 | 38 |
| 37 namespace remoting { | 39 namespace remoting { |
| 38 | 40 |
| 39 class AudioPacket; | 41 class AudioPacket; |
| 42 class AudioScheduler; |
| 40 class ClientSession; | 43 class ClientSession; |
| 41 class IpcAudioCapturer; | |
| 42 class IpcVideoFrameCapturer; | 44 class IpcVideoFrameCapturer; |
| 45 class VideoScheduler; |
| 43 | 46 |
| 44 // This class routes calls to the DesktopEnvironment's stubs though the IPC | 47 // This class routes calls to the DesktopEnvironment's stubs though the IPC |
| 45 // channel to the DesktopSessionAgent instance running in the desktop | 48 // channel to the DesktopSessionAgent instance running in the desktop |
| 46 // integration process. | 49 // integration process. |
| 47 class DesktopSessionProxy | 50 class DesktopSessionProxy |
| 48 : public base::RefCountedThreadSafe<DesktopSessionProxy>, | 51 : public base::RefCountedThreadSafe<DesktopSessionProxy>, |
| 52 public DesktopEnvironment, |
| 49 public IPC::Listener { | 53 public IPC::Listener { |
| 50 public: | 54 public: |
| 51 DesktopSessionProxy( | 55 DesktopSessionProxy( |
| 52 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, | |
| 53 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 54 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner); | 57 const std::string& client_jid, |
| 58 const base::Closure& disconnect_callback); |
| 59 |
| 60 // protocol::ClipboardStub implementation. |
| 61 virtual void InjectClipboardEvent( |
| 62 const protocol::ClipboardEvent& event) OVERRIDE; |
| 63 |
| 64 // protocol::InputStub implementation. |
| 65 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE; |
| 66 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE; |
| 67 |
| 68 // DesktopEnvironment implementation. |
| 69 virtual void StartAudio( |
| 70 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 71 scoped_ptr<AudioEncoder> audio_encoder, |
| 72 protocol::AudioStub* audio_stub) OVERRIDE; |
| 73 virtual void PauseAudio(bool pause) OVERRIDE; |
| 74 virtual void StartInput( |
| 75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 76 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 77 protocol::ClipboardStub* clipboard_stub) OVERRIDE; |
| 78 virtual void StartVideo( |
| 79 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 80 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 81 scoped_ptr<VideoEncoder> video_encoder, |
| 82 protocol::CursorShapeStub* cursor_shape_stub, |
| 83 protocol::VideoStub* video_stub) OVERRIDE; |
| 84 virtual SkISize GetScreenSize() const OVERRIDE; |
| 85 virtual void PauseVideo(bool pause) OVERRIDE; |
| 86 virtual void UpdateSequenceNumber(int64 sequence_number) OVERRIDE; |
| 55 | 87 |
| 56 // IPC::Listener implementation. | 88 // IPC::Listener implementation. |
| 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 58 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 90 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 59 virtual void OnChannelError() OVERRIDE; | 91 virtual void OnChannelError() OVERRIDE; |
| 60 | 92 |
| 61 // Initializes the object. |client_jid| specifies the client session's JID. | 93 // Stops audio/video schedulers and input handling. |
| 62 // |disconnect_callback| specifies a callback that disconnects the client | 94 void Stop(); |
| 63 // session when invoked. | |
| 64 // Initialize() should be called before AttachToDesktop() is called. | |
| 65 void Initialize(const std::string& client_jid, | |
| 66 const base::Closure& disconnect_callback); | |
| 67 | 95 |
| 68 // Connects to the desktop session agent. | 96 // Connects to the desktop session agent. |
| 69 bool AttachToDesktop(IPC::PlatformFileForTransit desktop_process, | 97 bool AttachToDesktop(IPC::PlatformFileForTransit desktop_process, |
| 70 IPC::PlatformFileForTransit desktop_pipe); | 98 IPC::PlatformFileForTransit desktop_pipe); |
| 71 | 99 |
| 72 // Closes the connection to the desktop session agent and cleans up | 100 // Closes the connection to the desktop session agent and cleans up |
| 73 // the associated resources. | 101 // the associated resources. |
| 74 void DetachFromDesktop(); | 102 void DetachFromDesktop(); |
| 75 | 103 |
| 76 // Disconnects the client session that owns |this|. | 104 // Disconnects the client session that owns |this|. |
| 77 void DisconnectSession(); | 105 void DisconnectSession(); |
| 78 | 106 |
| 79 // APIs used to implement the VideoFrameCapturer interface. These must be | 107 // APIs used to implement the VideoFrameCapturer interface. These must be |
| 80 // called on |video_capture_task_runner_|. | 108 // called on |video_capture_task_runner_|. |
| 81 void InvalidateRegion(const SkRegion& invalid_region); | 109 void InvalidateRegion(const SkRegion& invalid_region); |
| 82 void CaptureFrame(); | 110 void CaptureFrame(); |
| 83 | 111 |
| 84 // Stores |audio_capturer| to be used to post captured audio packets. | 112 // Stores |audio_packet_callback| to be used to post captured audio packets. |
| 85 // |audio_capturer| must be valid until StopAudioCapturer() is called. | 113 void StartAudioCapturer( |
| 86 void StartAudioCapturer(IpcAudioCapturer* audio_capturer); | 114 const AudioCapturer::PacketCapturedCallback& audio_packet_callback); |
| 87 | 115 |
| 88 // Clears the cached pointer to the audio capturer. Any packets captured after | 116 // Clears |audio_packet_callback_|. Any packets captured after |
| 89 // StopAudioCapturer() has been called will be silently dropped. | 117 // StopAudioCapturer() has been called will be silently dropped. |
| 90 void StopAudioCapturer(); | 118 void StopAudioCapturer(); |
| 91 | 119 |
| 92 // Stores |video_capturer| to be used to post captured video frames. | 120 // Stores |video_capturer| to be used to post captured video frames. |
| 93 // |video_capturer| must be valid until StopVideoCapturer() is called. | 121 // |video_capturer| must be valid until StopVideoCapturer() is called. |
| 94 void StartVideoCapturer(IpcVideoFrameCapturer* video_capturer); | 122 void StartVideoCapturer(IpcVideoFrameCapturer* video_capturer); |
| 95 | 123 |
| 96 // Clears the cached pointer to the video capturer. Any frames captured after | 124 // Clears the cached pointer to the video capturer. Any frames captured after |
| 97 // StopVideoCapturer() has been called will be silently dropped. | 125 // StopVideoCapturer() has been called will be silently dropped. |
| 98 void StopVideoCapturer(); | 126 void StopVideoCapturer(); |
| 99 | 127 |
| 100 // APIs used to implement the EventExecutor interface. | |
| 101 void InjectClipboardEvent(const protocol::ClipboardEvent& event); | |
| 102 void InjectKeyEvent(const protocol::KeyEvent& event); | |
| 103 void InjectMouseEvent(const protocol::MouseEvent& event); | |
| 104 void StartEventExecutor(scoped_ptr<protocol::ClipboardStub> client_clipboard); | |
| 105 | |
| 106 private: | 128 private: |
| 107 friend class base::RefCountedThreadSafe<DesktopSessionProxy>; | 129 friend class base::RefCountedThreadSafe<DesktopSessionProxy>; |
| 108 virtual ~DesktopSessionProxy(); | 130 virtual ~DesktopSessionProxy(); |
| 109 | 131 |
| 110 // Returns a shared buffer from the list of known buffers. | 132 // Returns a shared buffer from the list of known buffers. |
| 111 scoped_refptr<SharedBuffer> GetSharedBuffer(int id); | 133 scoped_refptr<SharedBuffer> GetSharedBuffer(int id); |
| 112 | 134 |
| 113 // Handles AudioPacket notification from the desktop session agent. | 135 // Handles AudioPacket notification from the desktop session agent. |
| 114 void OnAudioPacket(const std::string& serialized_packet); | 136 void OnAudioPacket(const std::string& serialized_packet); |
| 115 | 137 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Task runner on which methods of |audio_capturer_| will be invoked. | 171 // Task runner on which methods of |audio_capturer_| will be invoked. |
| 150 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner_; | 172 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner_; |
| 151 | 173 |
| 152 // Task runner on which public methods of this class should be called (unless | 174 // Task runner on which public methods of this class should be called (unless |
| 153 // it is documented otherwise). | 175 // it is documented otherwise). |
| 154 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 176 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 155 | 177 |
| 156 // Task runner on which methods of |video_capturer_| will be invoked. | 178 // Task runner on which methods of |video_capturer_| will be invoked. |
| 157 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; | 179 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; |
| 158 | 180 |
| 159 // Points to the audio capturer receiving captured audio packets. | 181 // Schedulers for audio and video capture. |
| 160 IpcAudioCapturer* audio_capturer_; | 182 scoped_refptr<AudioScheduler> audio_scheduler_; |
| 183 scoped_refptr<VideoScheduler> video_scheduler_; |
| 161 | 184 |
| 162 // Points to the client stub passed to StartEventExecutor(). | 185 // Invoked when an audio packet was received. |
| 163 scoped_ptr<protocol::ClipboardStub> client_clipboard_; | 186 AudioCapturer::PacketCapturedCallback audio_packet_callback_; |
| 187 |
| 188 // Points to the client stub passed to StartInput(). |
| 189 protocol::ClipboardStub* clipboard_stub_; |
| 164 | 190 |
| 165 // JID of the client session. | 191 // JID of the client session. |
| 166 std::string client_jid_; | 192 std::string client_jid_; |
| 167 | 193 |
| 168 // IPC channel to the desktop session agent. | 194 // IPC channel to the desktop session agent. |
| 169 scoped_ptr<IPC::ChannelProxy> desktop_channel_; | 195 scoped_ptr<IPC::ChannelProxy> desktop_channel_; |
| 170 | 196 |
| 171 // Disconnects the client session when invoked. | 197 // Disconnects the client session when invoked. |
| 172 base::Closure disconnect_callback_; | 198 base::Closure disconnect_callback_; |
| 173 | 199 |
| 174 #if defined(OS_WIN) | 200 #if defined(OS_WIN) |
| 175 // Handle of the desktop process. | 201 // Handle of the desktop process. |
| 176 base::win::ScopedHandle desktop_process_; | 202 base::win::ScopedHandle desktop_process_; |
| 177 #endif // defined(OS_WIN) | 203 #endif // defined(OS_WIN) |
| 178 | 204 |
| 179 int pending_capture_frame_requests_; | 205 int pending_capture_frame_requests_; |
| 180 | 206 |
| 181 typedef std::map<int, scoped_refptr<SharedBuffer> > SharedBuffers; | 207 typedef std::map<int, scoped_refptr<SharedBuffer> > SharedBuffers; |
| 182 SharedBuffers shared_buffers_; | 208 SharedBuffers shared_buffers_; |
| 183 | 209 |
| 184 // Points to the video capturer receiving captured video frames. | 210 // Points to the video capturer receiving captured video frames. |
| 185 IpcVideoFrameCapturer* video_capturer_; | 211 IpcVideoFrameCapturer* video_capturer_; |
| 186 | 212 |
| 187 DISALLOW_COPY_AND_ASSIGN(DesktopSessionProxy); | 213 DISALLOW_COPY_AND_ASSIGN(DesktopSessionProxy); |
| 188 }; | 214 }; |
| 189 | 215 |
| 190 } // namespace remoting | 216 } // namespace remoting |
| 191 | 217 |
| 192 #endif // REMOTING_HOST_DESKTOP_SESSION_PROXY_H_ | 218 #endif // REMOTING_HOST_DESKTOP_SESSION_PROXY_H_ |
| OLD | NEW |