Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1144)

Side by Side Diff: remoting/host/cast_extension_session.h

Issue 399253002: CastExtension Impl for Chromoting Host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes based on review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_HOST_CAST_EXTENSION_SESSION_H_
6 #define REMOTING_HOST_CAST_EXTENSION_SESSION_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h"
13 #include "base/timer/timer.h"
14 #include "base/values.h"
15 #include "jingle/glue/thread_wrapper.h"
16 #include "remoting/host/host_extension_session.h"
17 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
18 #include "third_party/webrtc/base/scoped_ref_ptr.h"
19 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
20
21 namespace base {
22 class SingleThreadTaskRunner;
23 class WaitableEvent;
24 } // namespace base
25
26 namespace net {
27 class URLRequestContextGetter;
28 } // namespace net
29
30 namespace webrtc {
31 class MediaStreamInterface;
32 } // namespace webrtc
33
34 namespace remoting {
35
36 namespace protocol {
37 class CursorShapeInfo;
38 struct NetworkSettings;
39 } // namespace protocol
40
41 // A HostExtensionSession implementation that enables WebRTC support using
42 // the PeerConnection native API.
43 class CastExtensionSession : public HostExtensionSession,
44 public webrtc::PeerConnectionObserver,
45 public webrtc::ScreenCapturer::MouseShapeObserver {
46 public:
47 virtual ~CastExtensionSession();
48
49 // Creates and returns a CastExtensionSession object, after performing
50 // initialization steps on it. The caller must take ownership of the returned
51 // object.
52 static scoped_ptr<CastExtensionSession> Create(
53 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
54 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
55 const protocol::NetworkSettings& network_settings,
56 ClientSessionControl* client_session_control,
57 protocol::ClientStub* client_stub);
58
59 // Called by webrtc::CreateSessionDescriptionObserver implementation.
60 void OnCreateSessionDescription(webrtc::SessionDescriptionInterface* desc);
61 void OnCreateSessionDescriptionFailure(const std::string& error);
62
63 // HostExtensionSession interface.
64 virtual scoped_ptr<webrtc::ScreenCapturer> OnCreateVideoCapturer(
65 scoped_ptr<webrtc::ScreenCapturer> capturer) OVERRIDE;
66 virtual bool ModifiesVideoPipeline() const OVERRIDE;
67 virtual bool OnExtensionMessage(
68 ClientSessionControl* client_session_control,
69 protocol::ClientStub* client_stub,
70 const protocol::ExtensionMessage& message) OVERRIDE;
71
72 // webrtc::ScreenCapturer::MouseShapeObserver interface.
Wez 2014/08/12 22:15:01 Hmmm, you shouldn't be using MouseShapeObserver si
aiguha 2014/08/13 18:33:28 Removed for now as suggested in .cc.
73 virtual void OnCursorShapeChanged(
74 webrtc::MouseCursorShape* cursor_shape) OVERRIDE;
75
76 // webrtc::PeerConnectionObserver interface.
77 virtual void OnError() OVERRIDE;
78 virtual void OnSignalingChange(
79 webrtc::PeerConnectionInterface::SignalingState new_state) OVERRIDE;
80 virtual void OnStateChange(
81 webrtc::PeerConnectionObserver::StateType state_changed) OVERRIDE;
82 virtual void OnAddStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
83 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
84 virtual void OnDataChannel(
85 webrtc::DataChannelInterface* data_channel) OVERRIDE;
86 virtual void OnRenegotiationNeeded() OVERRIDE;
87 virtual void OnIceConnectionChange(
88 webrtc::PeerConnectionInterface::IceConnectionState new_state) OVERRIDE;
89 virtual void OnIceGatheringChange(
90 webrtc::PeerConnectionInterface::IceGatheringState new_state) OVERRIDE;
91 virtual void OnIceCandidate(
92 const webrtc::IceCandidateInterface* candidate) OVERRIDE;
93 virtual void OnIceComplete() OVERRIDE;
94
95 private:
96 CastExtensionSession(
97 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
98 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
99 const protocol::NetworkSettings& network_settings,
100 ClientSessionControl* client_session_control,
101 protocol::ClientStub* client_stub);
102
103 // Parses |message| for a Session Description and sets the remote
104 // description, returning true if successful.
105 bool ParseAndSetRemoteDescription(base::DictionaryValue* message);
106
107 // Parses |message| for a PeerConnection ICE candidate and adds it to the
108 // Peer Connection, returning true if successful.
109 bool ParseAndAddICECandidate(base::DictionaryValue* message);
110
111 // Sends a message to the client through |client_stub_|. This method must be
112 // called on the network thread.
113 bool SendMessageToClient(const std::string& subject, const std::string& data);
114
115 // Sends the new |cursor_shape| using the ClientStub through
116 // |client_session_|. This method must be called on the network thread.
117 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
118
119 // Creates the jingle wrapper for the current thread, sets send to allowed,
120 // and saves a pointer to the relevant thread pointer in ptr. If |event|
121 // is not NULL, signals the event on completion.
122 void EnsureTaskAndSetSend(rtc::Thread** ptr,
123 base::WaitableEvent* event = NULL);
124
125 // Wraps each task runner in JingleThreadWrapper using EnsureTaskAndSetSend(),
126 // returning true if successful. Wrapping the task runners allows them to be
127 // shared with and used by the (about to be created) PeerConnectionFactory.
128 bool WrapTasksAndSave();
129
130 // Initializes PeerConnectionFactory and PeerConnection and sends a "ready"
131 // message to client. Returns true if these steps are performed successfully.
132 bool InitializePeerConnection();
133
134 // Constructs a CastVideoCapturerAdapter, a VideoSource, a VideoTrack and a
135 // MediaStream |stream_|, which it adds to the |peer_connection_|. Returns
136 // true if these steps are performed successfully. This method is called only
137 // when a PeerConnection offer is received from the client.
138 bool SetupVideoStream(scoped_ptr<webrtc::ScreenCapturer> screen_capturer);
139
140 // Polls a single stats report from the PeerConnection immediately. Called
141 // periodically using |stats_polling_timer_| after a PeerConnection has been
142 // established.
143 void PollPeerConnectionStats();
144
145 // Explicitly sets |peer_conn_factory_|, |peer_connection_| and |stream_| to
146 // NULL.
Wez 2014/08/12 22:15:01 Rather than "sets to nULL", suggest "releases |pee
aiguha 2014/08/13 18:33:28 Done.
147 void CleanupPeerConnection();
148
149 // Check if the connection is active.
150 bool connection_active() const;
151
152 // TaskRunners that will be used to setup the PeerConnectionFactory's
153 // signalling thread and worker thread respectively.
154 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
155 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
156
157 // Objects related to the WebRTC PeerConnection.
158 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
159 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_conn_factory_;
160 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_;
161
162 // Parameters passed to ChromiumPortAllocatorFactory on creation.
163 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
164 const protocol::NetworkSettings& network_settings_;
165
166 // Interface to interact with ClientSession.
167 ClientSessionControl* client_session_control_;
168
169 // Interface through which messages can be sent to the client.
170 protocol::ClientStub* client_stub_;
171
172 // Used to track webrtc connection statistics.
173 rtc::scoped_refptr<webrtc::StatsObserver> stats_observer_;
174
175 // Used to repeatedly poll stats from the |peer_connection_|.
176 base::RepeatingTimer<CastExtensionSession> stats_polling_timer_;
177
178 // True if a PeerConnection offer from the client has been received. This
179 // necessarily means that the host is not the caller in this attempted
180 // peer connection.
181 bool received_offer_;
182
183 // True if the webrtc::ScreenCapturer has been grabbed through the
184 // OnCreateVideoCapturer() callback.
185 bool has_grabbed_capturer_;
186
187 // PeerConnection signaling and worker threads created from
188 // JingleThreadWrappers. Each is created by calling
189 // jingle_glue::EnsureForCurrentMessageLoop() and thus deletes itself
190 // automatically when the associated MessageLoop is destroyed.
191 rtc::Thread* network_thread_wrapper_;
192 rtc::Thread* worker_thread_wrapper_;
193
194 // Worker thread that is wrapped to create |worker_thread_wrapper_|.
195 base::Thread worker_thread_;
196
197 DISALLOW_COPY_AND_ASSIGN(CastExtensionSession);
198 };
199
200 } // namespace remoting
201
202 #endif // REMOTING_HOST_CAST_EXTENSION_SESSION_H_
203
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698