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

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

Powered by Google App Engine
This is Rietveld 408576698