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

Side by Side Diff: content/renderer/media/rtc_peer_connection_handler.h

Issue 675013005: Split libjingle's signaling thread from the UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase after landing data channel change Created 6 years, 1 month 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
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 CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_ 6 #define CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.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/weak_ptr.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread.h"
17 #include "base/threading/thread_checker.h"
14 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
15 #include "content/renderer/media/webrtc/media_stream_track_metrics.h" 19 #include "content/renderer/media/webrtc/media_stream_track_metrics.h"
16 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h" 20 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h"
17 #include "third_party/WebKit/public/platform/WebRTCStatsRequest.h" 21 #include "third_party/WebKit/public/platform/WebRTCStatsRequest.h"
18 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" 22 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h"
19 23
20 namespace blink { 24 namespace blink {
21 class WebFrame; 25 class WebFrame;
22 class WebRTCDataChannelHandler; 26 class WebRTCDataChannelHandler;
23 class WebRTCOfferOptions; 27 class WebRTCOfferOptions;
24 } 28 }
25 29
26 namespace content { 30 namespace content {
27 31
28 class PeerConnectionDependencyFactory; 32 class PeerConnectionDependencyFactory;
29 class PeerConnectionTracker; 33 class PeerConnectionTracker;
30 class RemoteMediaStreamImpl; 34 class RemoteMediaStreamImpl;
35 class RtcDataChannelHandler;
31 class RTCMediaConstraints; 36 class RTCMediaConstraints;
32 class WebRtcMediaStreamAdapter; 37 class WebRtcMediaStreamAdapter;
33 38
34 // Mockable wrapper for blink::WebRTCStatsResponse 39 // Mockable wrapper for blink::WebRTCStatsResponse
35 class CONTENT_EXPORT LocalRTCStatsResponse 40 class CONTENT_EXPORT LocalRTCStatsResponse
36 : public NON_EXPORTED_BASE(rtc::RefCountInterface) { 41 : public NON_EXPORTED_BASE(rtc::RefCountInterface) {
37 public: 42 public:
38 explicit LocalRTCStatsResponse(const blink::WebRTCStatsResponse& impl) 43 explicit LocalRTCStatsResponse(const blink::WebRTCStatsResponse& impl)
39 : impl_(impl) { 44 : impl_(impl) {
40 } 45 }
(...skipping 24 matching lines...) Expand all
65 virtual bool hasSelector() const; 70 virtual bool hasSelector() const;
66 virtual blink::WebMediaStreamTrack component() const; 71 virtual blink::WebMediaStreamTrack component() const;
67 virtual void requestSucceeded(const LocalRTCStatsResponse* response); 72 virtual void requestSucceeded(const LocalRTCStatsResponse* response);
68 virtual scoped_refptr<LocalRTCStatsResponse> createResponse(); 73 virtual scoped_refptr<LocalRTCStatsResponse> createResponse();
69 74
70 protected: 75 protected:
71 ~LocalRTCStatsRequest() override; 76 ~LocalRTCStatsRequest() override;
72 77
73 private: 78 private:
74 blink::WebRTCStatsRequest impl_; 79 blink::WebRTCStatsRequest impl_;
75 rtc::scoped_refptr<LocalRTCStatsResponse> response_;
76 }; 80 };
77 81
78 // RTCPeerConnectionHandler is a delegate for the RTC PeerConnection API 82 // RTCPeerConnectionHandler is a delegate for the RTC PeerConnection API
79 // messages going between WebKit and native PeerConnection in libjingle. It's 83 // messages going between WebKit and native PeerConnection in libjingle. It's
80 // owned by WebKit. 84 // owned by WebKit.
81 // WebKit calls all of these methods on the main render thread. 85 // WebKit calls all of these methods on the main render thread.
82 // Callbacks to the webrtc::PeerConnectionObserver implementation also occur on 86 // Callbacks to the webrtc::PeerConnectionObserver implementation also occur on
83 // the main render thread. 87 // the main render thread.
84 class CONTENT_EXPORT RTCPeerConnectionHandler 88 class CONTENT_EXPORT RTCPeerConnectionHandler
85 : NON_EXPORTED_BASE(public blink::WebRTCPeerConnectionHandler), 89 : NON_EXPORTED_BASE(public blink::WebRTCPeerConnectionHandler) {
86 NON_EXPORTED_BASE(public webrtc::PeerConnectionObserver) {
87 public: 90 public:
88 RTCPeerConnectionHandler( 91 RTCPeerConnectionHandler(
89 blink::WebRTCPeerConnectionHandlerClient* client, 92 blink::WebRTCPeerConnectionHandlerClient* client,
90 PeerConnectionDependencyFactory* dependency_factory); 93 PeerConnectionDependencyFactory* dependency_factory,
94 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread);
91 virtual ~RTCPeerConnectionHandler(); 95 virtual ~RTCPeerConnectionHandler();
92 96
93 // Destroy all existing RTCPeerConnectionHandler objects. 97 // Destroy all existing RTCPeerConnectionHandler objects.
94 static void DestructAllHandlers(); 98 static void DestructAllHandlers();
95 99
96 static void ConvertOfferOptionsToConstraints( 100 static void ConvertOfferOptionsToConstraints(
97 const blink::WebRTCOfferOptions& options, 101 const blink::WebRTCOfferOptions& options,
98 RTCMediaConstraints* output); 102 RTCMediaConstraints* output);
99 103
100 void associateWithFrame(blink::WebFrame* frame); 104 void associateWithFrame(blink::WebFrame* frame);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const blink::WebMediaStream& stream) override; 155 const blink::WebMediaStream& stream) override;
152 virtual void getStats( 156 virtual void getStats(
153 const blink::WebRTCStatsRequest& request) override; 157 const blink::WebRTCStatsRequest& request) override;
154 virtual blink::WebRTCDataChannelHandler* createDataChannel( 158 virtual blink::WebRTCDataChannelHandler* createDataChannel(
155 const blink::WebString& label, 159 const blink::WebString& label,
156 const blink::WebRTCDataChannelInit& init) override; 160 const blink::WebRTCDataChannelInit& init) override;
157 virtual blink::WebRTCDTMFSenderHandler* createDTMFSender( 161 virtual blink::WebRTCDTMFSenderHandler* createDTMFSender(
158 const blink::WebMediaStreamTrack& track) override; 162 const blink::WebMediaStreamTrack& track) override;
159 virtual void stop() override; 163 virtual void stop() override;
160 164
161 // webrtc::PeerConnectionObserver implementation
162 void OnError() override;
163 // Triggered when the SignalingState changed.
164 void OnSignalingChange(
165 webrtc::PeerConnectionInterface::SignalingState new_state) override;
166 void OnAddStream(webrtc::MediaStreamInterface* stream) override;
167 void OnRemoveStream(webrtc::MediaStreamInterface* stream) override;
168 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
169 void OnIceConnectionChange(
170 webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
171 void OnIceGatheringChange(
172 webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
173
174 void OnDataChannel(webrtc::DataChannelInterface* data_channel) override;
175 void OnRenegotiationNeeded() override;
176
177 // Delegate functions to allow for mocking of WebKit interfaces. 165 // Delegate functions to allow for mocking of WebKit interfaces.
178 // getStats takes ownership of request parameter. 166 // getStats takes ownership of request parameter.
179 virtual void getStats(LocalRTCStatsRequest* request); 167 virtual void getStats(const scoped_refptr<LocalRTCStatsRequest>& request);
180 168
181 // Calls GetStats on |native_peer_connection_|. 169 // Calls GetStats on |native_peer_connection_|.
182 void GetStats(webrtc::StatsObserver* observer, 170 void GetStats(webrtc::StatsObserver* observer,
183 webrtc::MediaStreamTrackInterface* track, 171 webrtc::MediaStreamTrackInterface* track,
184 webrtc::PeerConnectionInterface::StatsOutputLevel level); 172 webrtc::PeerConnectionInterface::StatsOutputLevel level);
185 173
186 // Tells the |client_| to close RTCPeerConnection. 174 // Tells the |client_| to close RTCPeerConnection.
187 void CloseClientPeerConnection(); 175 void CloseClientPeerConnection();
188 176
189 PeerConnectionTracker* peer_connection_tracker(); 177 PeerConnectionTracker* peer_connection_tracker();
190 178
191 protected: 179 protected:
192 webrtc::PeerConnectionInterface* native_peer_connection() { 180 webrtc::PeerConnectionInterface* native_peer_connection() {
193 return native_peer_connection_.get(); 181 return native_peer_connection_.get();
194 } 182 }
195 183
184 class Observer;
185 friend class Observer;
186
187 void OnSignalingChange(
188 webrtc::PeerConnectionInterface::SignalingState new_state);
189 void OnIceConnectionChange(
190 webrtc::PeerConnectionInterface::IceConnectionState new_state);
191 void OnIceGatheringChange(
192 webrtc::PeerConnectionInterface::IceGatheringState new_state);
193 void OnRenegotiationNeeded();
194 void OnAddStream(scoped_ptr<RemoteMediaStreamImpl> stream);
195 void OnRemoveStream(
196 const scoped_refptr<webrtc::MediaStreamInterface>& stream);
197 void OnDataChannel(scoped_ptr<RtcDataChannelHandler> handler);
198 void OnIceCandidate(const std::string& sdp, const std::string& sdp_mid,
199 int sdp_mline_index, int component, int address_family);
200
196 private: 201 private:
197 webrtc::SessionDescriptionInterface* CreateNativeSessionDescription( 202 webrtc::SessionDescriptionInterface* CreateNativeSessionDescription(
198 const blink::WebRTCSessionDescription& description, 203 const blink::WebRTCSessionDescription& description,
199 webrtc::SdpParseError* error); 204 webrtc::SdpParseError* error);
200 205
206 base::ThreadChecker thread_checker_;
207
201 // |client_| is a weak pointer, and is valid until stop() has returned. 208 // |client_| is a weak pointer, and is valid until stop() has returned.
202 blink::WebRTCPeerConnectionHandlerClient* client_; 209 blink::WebRTCPeerConnectionHandlerClient* client_;
203 210
204 // |dependency_factory_| is a raw pointer, and is valid for the lifetime of 211 // |dependency_factory_| is a raw pointer, and is valid for the lifetime of
205 // RenderThreadImpl. 212 // RenderThreadImpl.
206 PeerConnectionDependencyFactory* dependency_factory_; 213 PeerConnectionDependencyFactory* dependency_factory_;
207 214
208 blink::WebFrame* frame_; 215 blink::WebFrame* frame_;
209 216
217 // Libjingle's signaling thread.
218 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_;
219
210 ScopedVector<WebRtcMediaStreamAdapter> local_streams_; 220 ScopedVector<WebRtcMediaStreamAdapter> local_streams_;
211 221
212 PeerConnectionTracker* peer_connection_tracker_; 222 PeerConnectionTracker* peer_connection_tracker_;
213 223
214 MediaStreamTrackMetrics track_metrics_; 224 MediaStreamTrackMetrics track_metrics_;
215 225
216 // Counter for a UMA stat reported at destruction time. 226 // Counter for a UMA stat reported at destruction time.
217 int num_data_channels_created_; 227 int num_data_channels_created_;
218 228
219 // Counter for number of IPv4 and IPv6 local candidates. 229 // Counter for number of IPv4 and IPv6 local candidates.
220 int num_local_candidates_ipv4_; 230 int num_local_candidates_ipv4_;
221 int num_local_candidates_ipv6_; 231 int num_local_candidates_ipv6_;
222 232
223 // |native_peer_connection_| is the libjingle native PeerConnection object. 233 // |native_peer_connection_| is the libjingle native PeerConnection object.
224 scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection_; 234 scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection_;
235 scoped_refptr<Observer> peer_connection_observer_;
225 236
226 typedef std::map<webrtc::MediaStreamInterface*, 237 typedef std::map<webrtc::MediaStreamInterface*,
227 content::RemoteMediaStreamImpl*> RemoteStreamMap; 238 content::RemoteMediaStreamImpl*> RemoteStreamMap;
228 RemoteStreamMap remote_streams_; 239 RemoteStreamMap remote_streams_;
229 scoped_refptr<webrtc::UMAObserver> uma_observer_; 240 scoped_refptr<webrtc::UMAObserver> uma_observer_;
230 base::TimeTicks ice_connection_checking_start_; 241 base::TimeTicks ice_connection_checking_start_;
242 base::WeakPtrFactory<RTCPeerConnectionHandler> weak_factory_;
231 243
232 DISALLOW_COPY_AND_ASSIGN(RTCPeerConnectionHandler); 244 DISALLOW_COPY_AND_ASSIGN(RTCPeerConnectionHandler);
233 }; 245 };
234 246
235 } // namespace content 247 } // namespace content
236 248
237 #endif // CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_ 249 #endif // CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698