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

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: Incorporated New HostExtension Flow 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/bind.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/timer/timer.h"
13 #include "base/values.h"
14 #include "jingle/glue/thread_wrapper.h"
15 #include "remoting/base/auto_thread.h"
16 #include "remoting/host/host_extension_session.h"
17 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
Wez 2014/08/07 01:25:35 Forward define?
aiguha 2014/08/12 01:42:39 Done.
18 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
19 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h"
20 #include "third_party/libjingle/source/talk/media/base/videocapturer.h"
Wez 2014/08/07 01:25:35 Do you need this or could you forward-declare here
aiguha 2014/08/12 01:42:40 Left-over include actually. Removed!
21 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
22
23 namespace base {
24 class SingleThreadTaskRunner;
25 class WaitableEvent;
26 } // namespace base
27
28 namespace net {
29 class URLRequestContextGetter;
30 } // namespace net
31
32 namespace remoting {
33
34 namespace protocol {
35 class CursorShapeInfo;
36 struct NetworkSettings;
37 } // namespace protocol
38
39 // A class that extends HostExtensionSession to enable WebRTC support using
40 // the PeerConnection native APIs.
Wez 2014/08/07 01:25:34 Suggest "HostExtensionSession implementation that.
aiguha 2014/08/12 01:42:39 Done.
41 class CastExtensionSession : public HostExtensionSession,
42 public webrtc::PeerConnectionObserver,
43 public webrtc::ScreenCapturer::MouseShapeObserver {
44 public:
45 virtual ~CastExtensionSession();
46 // Creates and returns a CastExtensionSession object, after performing
Wez 2014/08/07 01:25:35 nit: Blank line between dtor and comment.
aiguha 2014/08/12 01:42:40 Done.
47 // initialization steps on it. The caller must take ownership of the returned
48 // object.
49 static CastExtensionSession* Create(
Wez 2014/08/07 01:25:35 scoped_ptr<CastExtensionSession>
aiguha 2014/08/12 01:42:40 I thought returning a scoped_ptr would be better t
Wez 2014/08/12 22:14:59 Those probably just pre-date scoped_ptr<> being su
aiguha 2014/08/13 18:33:27 Acknowledged.
50 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
Wez 2014/08/07 01:25:36 Is this TaskRunner used for WebRTC networking, or
aiguha 2014/08/12 01:42:39 This TaskRunner is used to send/receive ExtensionM
Wez 2014/08/12 22:15:00 That happens via the ClientStub, right? So from th
aiguha 2014/08/13 18:33:27 I see your point. Renamed this the caller_task_run
51 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
52 const protocol::NetworkSettings& network_settings,
53 ClientSessionControl* client_session_control,
54 protocol::ClientStub* client_stub);
55
56 // HostExtensionSession implementation.
Wez 2014/08/07 01:25:35 nit: Elsewhere in remoting we use "<Foo> interface
aiguha 2014/08/12 01:42:39 Acknowledged.
57 virtual bool OnExtensionMessage(
58 ClientSessionControl* client_session_control,
59 protocol::ClientStub* client_stub,
60 const protocol::ExtensionMessage& message) OVERRIDE;
61 virtual bool ModifiesVideoPipeline() const OVERRIDE;
62 virtual scoped_ptr<webrtc::ScreenCapturer> OnCreateVideoCapturer(
63 scoped_ptr<webrtc::ScreenCapturer> capturer) OVERRIDE;
Wez 2014/08/07 01:25:34 nit: It's usually a good idea to list interface ov
aiguha 2014/08/12 01:42:40 Done.
64
65 // PeerConnectionObserver implementation.
Wez 2014/08/07 01:25:35 nit: You mean webrtc::PeerConnectionObserver?
aiguha 2014/08/12 01:42:41 Yes, my mistake. Fixed!
66 virtual void OnError() OVERRIDE;
67 virtual void OnSignalingChange(
68 webrtc::PeerConnectionInterface::SignalingState new_state) OVERRIDE;
69 virtual void OnStateChange(
70 webrtc::PeerConnectionObserver::StateType state_changed) OVERRIDE;
71 virtual void OnAddStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
72 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) OVERRIDE;
73 virtual void OnDataChannel(
74 webrtc::DataChannelInterface* data_channel) OVERRIDE;
75 virtual void OnRenegotiationNeeded() OVERRIDE;
76 virtual void OnIceConnectionChange(
77 webrtc::PeerConnectionInterface::IceConnectionState new_state) OVERRIDE;
78 virtual void OnIceGatheringChange(
79 webrtc::PeerConnectionInterface::IceGatheringState new_state) OVERRIDE;
80 virtual void OnIceCandidate(
81 const webrtc::IceCandidateInterface* candidate) OVERRIDE;
82 virtual void OnIceComplete() OVERRIDE;
83
84 // MouseShapeObserver implementation.
Wez 2014/08/07 01:25:34 Suggest moving this interface definition up nearer
aiguha 2014/08/12 01:42:39 Done.
85 virtual void OnCursorShapeChanged(
86 webrtc::MouseCursorShape* cursor_shape) OVERRIDE;
87
88 // Called by webrtc::CreateSessionDescriptionObserver implementation.
89 void OnSuccess(webrtc::SessionDescriptionInterface* desc);
90 void OnFailure(const std::string& error);
Wez 2014/08/07 01:25:35 Suggest renaming these "OnSessionDescription" and
Wez 2014/08/07 01:25:35 So are they part of some specific interface? Or do
aiguha 2014/08/12 01:42:39 Done.
aiguha 2014/08/12 01:42:41 They're not part of an interface, but callbacks (c
91
92 private:
93 CastExtensionSession(
94 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
95 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
96 const protocol::NetworkSettings& network_settings,
97 ClientSessionControl* client_session_control,
98 protocol::ClientStub* client_stub);
99
100 // Parses |message| for a Session Description and sets the remote
101 // description, returning true if successful.
102 bool ParseAndSetRemoteDescription(base::DictionaryValue* message);
Wez 2014/08/07 01:25:35 Could this be a const base::DictionaryValue&, here
aiguha 2014/08/12 01:42:40 No, because we use GetDictionary() which is not ma
103
104 // Parses |message| for a PeerConnection ICE candidate and adds it to the
105 // Peer Connection, returning true if successful.
106 bool ParseAndAddICECandidate(base::DictionaryValue* message);
107
108 // Sends messages to client using the ClientStub through |client_session_|.
Wez 2014/08/07 01:25:35 s/messages/a message?
Wez 2014/08/07 01:25:36 you don't have |client_session_| any more, so I th
aiguha 2014/08/12 01:42:40 Yes, forgot to update the comment, thanks!
aiguha 2014/08/12 01:42:41 Done.
109 // |data| should be json formatted. This method must be called on the
110 // network thread.
Wez 2014/08/07 01:25:35 s/network/caller
Wez 2014/08/07 01:25:36 What are the threading requirements of all the oth
aiguha 2014/08/12 01:42:39 The only threading requirements are that chromotin
Wez 2014/08/12 22:14:59 This extension session object is an "owned" object
aiguha 2014/08/13 18:33:27 Yes, we've got the following: network thread (call
111 bool SendMessageToClient(const char* subject, const std::string& data);
Wez 2014/08/07 01:25:34 What does the |subject| parameter mean? Why is it
aiguha 2014/08/12 01:42:41 It's now std::string&, thanks for pointing that ou
Wez 2014/08/12 22:14:59 OK; I think the comment here should clarify what t
aiguha 2014/08/13 18:33:27 Totally agree! I realized that this is the best pl
112
113 // Sends the new |cursor_shape| using the ClientStub through
114 // |client_session_|.
Wez 2014/08/07 01:25:34 Must also be called on the caller thread?
aiguha 2014/08/12 01:42:40 Yes, will update!
115 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
116
117 // Creates the jingle wrapper for the current thread, sets send to allowed,
118 // and saves a pointer to the relevant thread pointer in ptr. If |event|
119 // is not NULL, signals the event on completion.
Wez 2014/08/07 01:25:35 Why would you ever not want to wait for completion
aiguha 2014/08/12 01:42:40 We need to EnsureTaskAndSetSend() for both threads
120 void EnsureTaskAndSetSend(talk_base::Thread** ptr,
121 base::WaitableEvent* event = NULL);
122
123 // Wraps each task runner in JingleThreadWrapper using EnsureTaskAndSetSend(),
124 // returning true if successful. Wrapping the task runners allows them to be
125 // shared with and used by the (about to be created) PeerConnectionFactory.
126 bool WrapTasksAndSave();
127
128 // Initializes PeerConnectionFactory and PeerConnection and sends a "ready"
129 // message to client. Returns true if these steps are performed successfully.
130 bool InitializePeerConnection();
131
132 // Sets |this| as the MouseShapeObserver of |screen_capturer|. Constructs a
Wez 2014/08/07 01:25:34 How is becoming the MouseShapeObserver part of set
aiguha 2014/08/12 01:42:39 SetupVideoStream() after we successfully grab the
133 // VideoSource, a VideoTrack and a MediaStream |stream_|, which it adds to
134 // the |peer_connection_|. Returns true if these steps are performed
135 // successfully. This method is called when only when a PeerConnection offer
136 // is received from the client.
137 bool SetupVideoStream(scoped_ptr<webrtc::ScreenCapturer> screen_capturer);
138
139 // Polls a single stats report from the PeerConnection immediately. Called
140 // periodically using |stats_polling_timer_| after a PeerConnection has been
141 // established.
142 void PollPeerConnectionStats();
143
144 // Explicitly sets |peer_conn_factory_|, |peer_connection_| and |stream_| to
145 // NULL.
Wez 2014/08/07 01:25:34 They are all ref-counted, though, so this won't ne
aiguha 2014/08/12 01:42:40 Agreed. Rename to CleanupPeerConnection()?
146 void DeletePeerConnection();
147
148 // Check if the connection is active.
149 bool connection_active() const;
150
151 // TaskRunner that will be used to setup the PeerConnectionFactory's
152 // signalling thread.
153 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
Wez 2014/08/07 01:25:34 Suggest keeping the network and worker task runner
aiguha 2014/08/12 01:42:40 Done.
154
155 // Objects related to the WebRTC PeerConnection.
156 talk_base::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
157 talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
158 peer_conn_factory_;
159 talk_base::scoped_refptr<webrtc::MediaStreamInterface> stream_;
160
161 // Parameters passed to ChromiumPortAllocatorFactory on creation.
162 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
163 const protocol::NetworkSettings& network_settings_;
164
165 // Interface to interact with the ClientSession.
166 ClientSessionControl* client_session_control_;
167
168 // Interface through which messages can be sent to the client.
169 protocol::ClientStub* client_stub_;
170
171 // Used to track webrtc connection statistics.
172 talk_base::scoped_refptr<webrtc::StatsObserver> stats_observer_;
173
174 // Used to repeatedly poll stats from the |peer_connection_|.
175 base::RepeatingTimer<CastExtensionSession> stats_polling_timer_;
176
177 // True if a PeerConnection offer from the client has been received. This
178 // necessarily means that the host is not the caller in this attempted
179 // peer connection.
180 bool received_offer_;
181
182 // True if the webrtc::ScreenCapturer has been grabbed through the
183 // OnCreateVideoCapturer() callback.
184 bool has_grabbed_capturer_;
185
186 // Jingle Thread wrappers for talk_base::Thread, to be used with
187 // PeerConnection API as well as |this| for signalling and worker
188 // threads.
189 // Created by calling jingle_glue::EnsureForCurrentMessageLoop() and thus
190 // deletes itself automatically when the associated MessageLoop is destroyed.
191 talk_base::Thread* network_thread_wrapper_;
192 talk_base::Thread* worker_thread_wrapper_;
193
194 scoped_refptr<AutoThreadTaskRunner> worker_task_runner_;
195
196 scoped_ptr<AutoThread> worker_thread_;
197
198 DISALLOW_COPY_AND_ASSIGN(CastExtensionSession);
199 };
200
201 } // namespace remoting
202
203 #endif // REMOTING_HOST_CAST_EXTENSION_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698