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

Side by Side Diff: webrtc/pc/channel.h

Issue 1903393004: Added network thread to rtc::BaseChannel (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 7 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
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/pc/channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_PC_CHANNEL_H_ 11 #ifndef WEBRTC_PC_CHANNEL_H_
12 #define WEBRTC_PC_CHANNEL_H_ 12 #define WEBRTC_PC_CHANNEL_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 #include <utility> 18 #include <utility>
19 #include <vector> 19 #include <vector>
20 20
21 #include "webrtc/audio_sink.h" 21 #include "webrtc/audio_sink.h"
22 #include "webrtc/base/asyncinvoker.h"
22 #include "webrtc/base/asyncudpsocket.h" 23 #include "webrtc/base/asyncudpsocket.h"
23 #include "webrtc/base/criticalsection.h" 24 #include "webrtc/base/criticalsection.h"
24 #include "webrtc/base/network.h" 25 #include "webrtc/base/network.h"
25 #include "webrtc/base/sigslot.h" 26 #include "webrtc/base/sigslot.h"
26 #include "webrtc/base/window.h" 27 #include "webrtc/base/window.h"
27 #include "webrtc/media/base/mediachannel.h" 28 #include "webrtc/media/base/mediachannel.h"
28 #include "webrtc/media/base/mediaengine.h" 29 #include "webrtc/media/base/mediaengine.h"
29 #include "webrtc/media/base/streamparams.h" 30 #include "webrtc/media/base/streamparams.h"
30 #include "webrtc/media/base/videosinkinterface.h" 31 #include "webrtc/media/base/videosinkinterface.h"
31 #include "webrtc/media/base/videosourceinterface.h" 32 #include "webrtc/media/base/videosourceinterface.h"
32 #include "webrtc/p2p/base/transportcontroller.h" 33 #include "webrtc/p2p/base/transportcontroller.h"
33 #include "webrtc/p2p/client/socketmonitor.h" 34 #include "webrtc/p2p/client/socketmonitor.h"
34 #include "webrtc/pc/audiomonitor.h" 35 #include "webrtc/pc/audiomonitor.h"
35 #include "webrtc/pc/bundlefilter.h" 36 #include "webrtc/pc/bundlefilter.h"
36 #include "webrtc/pc/mediamonitor.h" 37 #include "webrtc/pc/mediamonitor.h"
37 #include "webrtc/pc/mediasession.h" 38 #include "webrtc/pc/mediasession.h"
38 #include "webrtc/pc/rtcpmuxfilter.h" 39 #include "webrtc/pc/rtcpmuxfilter.h"
39 #include "webrtc/pc/srtpfilter.h" 40 #include "webrtc/pc/srtpfilter.h"
40 41
41 namespace webrtc { 42 namespace webrtc {
42 class AudioSinkInterface; 43 class AudioSinkInterface;
43 } // namespace webrtc 44 } // namespace webrtc
44 45
45 namespace cricket { 46 namespace cricket {
46 47
47 struct CryptoParams; 48 struct CryptoParams;
48 class MediaContentDescription; 49 class MediaContentDescription;
49 50
50 enum SinkType {
51 SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption.
52 SINK_POST_CRYPTO // Sink packets after encryption or before decryption.
53 };
54
55 // BaseChannel contains logic common to voice and video, including 51 // BaseChannel contains logic common to voice and video, including
56 // enable, marshaling calls to a worker thread, and 52 // enable, marshaling calls to a worker and network threads, and
57 // connection and media monitors. 53 // connection and media monitors.
54 // BaseChannel assumes signaling and other threads allowed to make synchronius
stefan-webrtc 2016/05/11 13:10:26 "...are allowed to make synchronous calls to the w
danilchap 2016/05/11 14:15:30 Thank you!
55 // calls to worker thread, worker thread make synchronius calls only
56 // to network thread, and network thread can't be blocked by other threads.
57 // All methods with _n suffix must be called on network thread,
58 // methods with _w suffix - on worker thread
59 // and methods with _s suffix on signaling thread.
60 // Network and worker threads may be the same thread.
58 // 61 //
59 // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS! 62 // WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
60 // This is required to avoid a data race between the destructor modifying the 63 // This is required to avoid a data race between the destructor modifying the
61 // vtable, and the media channel's thread using BaseChannel as the 64 // vtable, and the media channel's thread using BaseChannel as the
62 // NetworkInterface. 65 // NetworkInterface.
63 66
64 class BaseChannel 67 class BaseChannel
65 : public rtc::MessageHandler, public sigslot::has_slots<>, 68 : public rtc::MessageHandler, public sigslot::has_slots<>,
66 public MediaChannel::NetworkInterface, 69 public MediaChannel::NetworkInterface,
67 public ConnectionStatsGetter { 70 public ConnectionStatsGetter {
68 public: 71 public:
69 BaseChannel(rtc::Thread* thread, 72 BaseChannel(rtc::Thread* worker_thread,
73 rtc::Thread* network_thread,
70 MediaChannel* channel, 74 MediaChannel* channel,
71 TransportController* transport_controller, 75 TransportController* transport_controller,
72 const std::string& content_name, 76 const std::string& content_name,
73 bool rtcp); 77 bool rtcp);
74 virtual ~BaseChannel(); 78 virtual ~BaseChannel();
75 bool Init(); 79 bool Init_w();
76 // Deinit may be called multiple times and is simply ignored if it's alreay 80 // Deinit may be called multiple times and is simply ignored if it's already
77 // done. 81 // done.
78 void Deinit(); 82 void Deinit();
79 83
80 rtc::Thread* worker_thread() const { return worker_thread_; } 84 rtc::Thread* worker_thread() const { return worker_thread_; }
85 rtc::Thread* network_thread() const { return network_thread_; }
81 const std::string& content_name() const { return content_name_; } 86 const std::string& content_name() const { return content_name_; }
82 const std::string& transport_name() const { return transport_name_; } 87 const std::string& transport_name() const { return transport_name_; }
83 TransportChannel* transport_channel() const {
84 return transport_channel_;
85 }
86 TransportChannel* rtcp_transport_channel() const {
87 return rtcp_transport_channel_;
88 }
89 bool enabled() const { return enabled_; } 88 bool enabled() const { return enabled_; }
90 89
91 // This function returns true if we are using SRTP. 90 // This function returns true if we are using SRTP.
92 bool secure() const { return srtp_filter_.IsActive(); } 91 bool secure() const { return srtp_filter_.IsActive(); }
93 // The following function returns true if we are using 92 // The following function returns true if we are using
94 // DTLS-based keying. If you turned off SRTP later, however 93 // DTLS-based keying. If you turned off SRTP later, however
95 // you could have secure() == false and dtls_secure() == true. 94 // you could have secure() == false and dtls_secure() == true.
96 bool secure_dtls() const { return dtls_keyed_; } 95 bool secure_dtls() const { return dtls_keyed_; }
97 // This function returns true if we require secure channel for call setup. 96 // This function returns true if we require secure channel for call setup.
98 bool secure_required() const { return secure_required_; } 97 bool secure_required() const { return secure_required_; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 BundleFilter* bundle_filter() { return &bundle_filter_; } 135 BundleFilter* bundle_filter() { return &bundle_filter_; }
137 136
138 const std::vector<StreamParams>& local_streams() const { 137 const std::vector<StreamParams>& local_streams() const {
139 return local_streams_; 138 return local_streams_;
140 } 139 }
141 const std::vector<StreamParams>& remote_streams() const { 140 const std::vector<StreamParams>& remote_streams() const {
142 return remote_streams_; 141 return remote_streams_;
143 } 142 }
144 143
145 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure; 144 sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
146 void SignalDtlsSetupFailure_w(bool rtcp); 145 void SignalDtlsSetupFailure_n(bool rtcp);
147 void SignalDtlsSetupFailure_s(bool rtcp); 146 void SignalDtlsSetupFailure_s(bool rtcp);
148 147
149 // Used for latency measurements. 148 // Used for latency measurements.
150 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived; 149 sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
151 150
151 // Forward TransportChannel SignalSentPacket to worker thread.
152 sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
153
154 // Only public for unit tests. Otherwise, consider private.
155 TransportChannel* transport_channel() const { return transport_channel_; }
156 TransportChannel* rtcp_transport_channel() const {
157 return rtcp_transport_channel_;
158 }
159
152 // Made public for easier testing. 160 // Made public for easier testing.
153 void SetReadyToSend(bool rtcp, bool ready); 161 void SetReadyToSend(bool rtcp, bool ready);
154 162
155 // Only public for unit tests. Otherwise, consider protected. 163 // Only public for unit tests. Otherwise, consider protected.
156 int SetOption(SocketType type, rtc::Socket::Option o, int val) 164 int SetOption(SocketType type, rtc::Socket::Option o, int val)
157 override; 165 override;
166 int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
158 167
159 SrtpFilter* srtp_filter() { return &srtp_filter_; } 168 SrtpFilter* srtp_filter() { return &srtp_filter_; }
160 169
161 protected: 170 protected:
162 virtual MediaChannel* media_channel() const { return media_channel_; } 171 virtual MediaChannel* media_channel() const { return media_channel_; }
163 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |rtcp_| is 172 // Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |rtcp_| is
164 // true). Gets the transport channels from |transport_controller_|. 173 // true). Gets the transport channels from |transport_controller_|.
165 bool SetTransport_w(const std::string& transport_name); 174 bool SetTransport_n(const std::string& transport_name);
166 175
167 void set_transport_channel(TransportChannel* transport); 176 void SetTransportChannel_n(TransportChannel* transport);
168 void set_rtcp_transport_channel(TransportChannel* transport, 177 void SetRtcpTransportChannel_n(TransportChannel* transport,
169 bool update_writablity); 178 bool update_writablity);
170 179
171 bool was_ever_writable() const { return was_ever_writable_; } 180 bool was_ever_writable() const { return was_ever_writable_; }
172 void set_local_content_direction(MediaContentDirection direction) { 181 void set_local_content_direction(MediaContentDirection direction) {
173 local_content_direction_ = direction; 182 local_content_direction_ = direction;
174 } 183 }
175 void set_remote_content_direction(MediaContentDirection direction) { 184 void set_remote_content_direction(MediaContentDirection direction) {
176 remote_content_direction_ = direction; 185 remote_content_direction_ = direction;
177 } 186 }
178 void set_secure_required(bool secure_required) { 187 void set_secure_required(bool secure_required) {
179 secure_required_ = secure_required; 188 secure_required_ = secure_required;
180 } 189 }
181 bool IsReadyToReceive() const; 190 bool IsReadyToReceive_w() const;
182 bool IsReadyToSend() const; 191 bool IsReadyToSend_w() const;
183 rtc::Thread* signaling_thread() { 192 rtc::Thread* signaling_thread() {
184 return transport_controller_->signaling_thread(); 193 return transport_controller_->signaling_thread();
185 } 194 }
186 bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; } 195 bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; }
187 196
188 void ConnectToTransportChannel(TransportChannel* tc); 197 void ConnectToTransportChannel(TransportChannel* tc);
189 void DisconnectFromTransportChannel(TransportChannel* tc); 198 void DisconnectFromTransportChannel(TransportChannel* tc);
190 199
191 void FlushRtcpMessages(); 200 void FlushRtcpMessages_n();
192 201
193 // NetworkInterface implementation, called by MediaEngine 202 // NetworkInterface implementation, called by MediaEngine
194 bool SendPacket(rtc::CopyOnWriteBuffer* packet, 203 bool SendPacket(rtc::CopyOnWriteBuffer* packet,
195 const rtc::PacketOptions& options) override; 204 const rtc::PacketOptions& options) override;
196 bool SendRtcp(rtc::CopyOnWriteBuffer* packet, 205 bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
197 const rtc::PacketOptions& options) override; 206 const rtc::PacketOptions& options) override;
198 207
199 // From TransportChannel 208 // From TransportChannel
200 void OnWritableState(TransportChannel* channel); 209 void OnWritableState(TransportChannel* channel);
201 virtual void OnChannelRead(TransportChannel* channel, 210 virtual void OnChannelRead(TransportChannel* channel,
202 const char* data, 211 const char* data,
203 size_t len, 212 size_t len,
204 const rtc::PacketTime& packet_time, 213 const rtc::PacketTime& packet_time,
205 int flags); 214 int flags);
206 void OnReadyToSend(TransportChannel* channel); 215 void OnReadyToSend(TransportChannel* channel);
207 216
208 void OnDtlsState(TransportChannel* channel, DtlsTransportState state); 217 void OnDtlsState(TransportChannel* channel, DtlsTransportState state);
209 218
210 void OnSelectedCandidatePairChanged( 219 void OnSelectedCandidatePairChanged(
211 TransportChannel* channel, 220 TransportChannel* channel,
212 CandidatePairInterface* selected_candidate_pair, 221 CandidatePairInterface* selected_candidate_pair,
213 int last_sent_packet_id); 222 int last_sent_packet_id);
214 223
215 bool PacketIsRtcp(const TransportChannel* channel, const char* data, 224 bool PacketIsRtcp(const TransportChannel* channel, const char* data,
216 size_t len); 225 size_t len);
217 bool SendPacket(bool rtcp, 226 bool SendPacket(bool rtcp,
218 rtc::CopyOnWriteBuffer* packet, 227 rtc::CopyOnWriteBuffer* packet,
219 const rtc::PacketOptions& options); 228 const rtc::PacketOptions& options);
229
220 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); 230 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
221 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, 231 void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
222 const rtc::PacketTime& packet_time); 232 const rtc::PacketTime& packet_time);
233 void OnPacketReceived(bool rtcp,
234 const rtc::CopyOnWriteBuffer& packet,
235 const rtc::PacketTime& packet_time);
223 236
224 void EnableMedia_w(); 237 void EnableMedia_w();
225 void DisableMedia_w(); 238 void DisableMedia_w();
226 void UpdateWritableState_w(); 239 void UpdateWritableState_n();
227 void ChannelWritable_w(); 240 void ChannelWritable_n();
228 void ChannelNotWritable_w(); 241 void ChannelNotWritable_n();
229 bool AddRecvStream_w(const StreamParams& sp); 242 bool AddRecvStream_w(const StreamParams& sp);
230 bool RemoveRecvStream_w(uint32_t ssrc); 243 bool RemoveRecvStream_w(uint32_t ssrc);
231 bool AddSendStream_w(const StreamParams& sp); 244 bool AddSendStream_w(const StreamParams& sp);
232 bool RemoveSendStream_w(uint32_t ssrc); 245 bool RemoveSendStream_w(uint32_t ssrc);
233 virtual bool ShouldSetupDtlsSrtp() const; 246 virtual bool ShouldSetupDtlsSrtp_n() const;
234 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters. 247 // Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
235 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter. 248 // |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
236 bool SetupDtlsSrtp(bool rtcp_channel); 249 bool SetupDtlsSrtp_n(bool rtcp_channel);
237 void MaybeSetupDtlsSrtp_w(); 250 void MaybeSetupDtlsSrtp_n();
238 // Set the DTLS-SRTP cipher policy on this channel as appropriate. 251 // Set the DTLS-SRTP cipher policy on this channel as appropriate.
239 bool SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp); 252 bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
240 253
241 virtual void ChangeState() = 0; 254 void ChangeState();
255 virtual void ChangeState_w() = 0;
242 256
243 // Gets the content info appropriate to the channel (audio or video). 257 // Gets the content info appropriate to the channel (audio or video).
244 virtual const ContentInfo* GetFirstContent( 258 virtual const ContentInfo* GetFirstContent(
245 const SessionDescription* sdesc) = 0; 259 const SessionDescription* sdesc) = 0;
246 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, 260 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
247 ContentAction action, 261 ContentAction action,
248 std::string* error_desc); 262 std::string* error_desc);
249 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams, 263 bool UpdateRemoteStreams_w(const std::vector<StreamParams>& streams,
250 ContentAction action, 264 ContentAction action,
251 std::string* error_desc); 265 std::string* error_desc);
252 virtual bool SetLocalContent_w(const MediaContentDescription* content, 266 virtual bool SetLocalContent_w(const MediaContentDescription* content,
253 ContentAction action, 267 ContentAction action,
254 std::string* error_desc) = 0; 268 std::string* error_desc) = 0;
255 virtual bool SetRemoteContent_w(const MediaContentDescription* content, 269 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
256 ContentAction action, 270 ContentAction action,
257 std::string* error_desc) = 0; 271 std::string* error_desc) = 0;
258 bool SetRtpTransportParameters_w(const MediaContentDescription* content, 272 bool SetRtpTransportParameters(const MediaContentDescription* content,
273 ContentAction action,
274 ContentSource src,
275 std::string* error_desc);
276 bool SetRtpTransportParameters_n(const MediaContentDescription* content,
259 ContentAction action, 277 ContentAction action,
260 ContentSource src, 278 ContentSource src,
261 std::string* error_desc); 279 std::string* error_desc);
262 280
263 // Helper method to get RTP Absoulute SendTime extension header id if 281 // Helper method to get RTP Absoulute SendTime extension header id if
264 // present in remote supported extensions list. 282 // present in remote supported extensions list.
265 void MaybeCacheRtpAbsSendTimeHeaderExtension( 283 void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
266 const std::vector<RtpHeaderExtension>& extensions); 284 const std::vector<RtpHeaderExtension>& extensions);
267 285
268 bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, 286 bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
269 bool* dtls, 287 bool* dtls,
270 std::string* error_desc); 288 std::string* error_desc);
271 bool SetSrtp_w(const std::vector<CryptoParams>& params, 289 bool SetSrtp_n(const std::vector<CryptoParams>& params,
272 ContentAction action, 290 ContentAction action,
273 ContentSource src, 291 ContentSource src,
274 std::string* error_desc); 292 std::string* error_desc);
275 void ActivateRtcpMux_w(); 293 void ActivateRtcpMux_n();
276 bool SetRtcpMux_w(bool enable, 294 bool SetRtcpMux_n(bool enable,
277 ContentAction action, 295 ContentAction action,
278 ContentSource src, 296 ContentSource src,
279 std::string* error_desc); 297 std::string* error_desc);
280 298
281 // From MessageHandler 299 // From MessageHandler
282 void OnMessage(rtc::Message* pmsg) override; 300 void OnMessage(rtc::Message* pmsg) override;
283 301
284 // Handled in derived classes 302 // Handled in derived classes
285 // Get the SRTP crypto suites to use for RTP media 303 // Get the SRTP crypto suites to use for RTP media
286 virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const = 0; 304 virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
287 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor, 305 virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
288 const std::vector<ConnectionInfo>& infos) = 0; 306 const std::vector<ConnectionInfo>& infos) = 0;
289 307
290 // Helper function for invoking bool-returning methods on the worker thread. 308 // Helper function for invoking bool-returning methods on the worker thread.
291 template <class FunctorT> 309 template <class FunctorT>
292 bool InvokeOnWorker(const FunctorT& functor) { 310 bool InvokeOnWorker(const FunctorT& functor) {
293 return worker_thread_->Invoke<bool>(functor); 311 return worker_thread_->Invoke<bool>(functor);
294 } 312 }
295 313
296 private: 314 private:
297 rtc::Thread* worker_thread_; 315 bool InitNetwork_n();
298 TransportController* transport_controller_; 316 void DeinitNetwork_n();
299 MediaChannel* media_channel_; 317 void SignalSentPacket_n(TransportChannel* channel,
300 std::vector<StreamParams> local_streams_; 318 const rtc::SentPacket& sent_packet);
301 std::vector<StreamParams> remote_streams_; 319 void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
320 bool IsTransportReadyToSend_n() const;
321 void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
322
323 rtc::Thread* const worker_thread_;
324 rtc::Thread* const network_thread_;
325 rtc::AsyncInvoker invoker_;
302 326
303 const std::string content_name_; 327 const std::string content_name_;
328 std::unique_ptr<ConnectionMonitor> connection_monitor_;
329
330 // Transport related members that should be accessed from network thread.
331 TransportController* const transport_controller_;
304 std::string transport_name_; 332 std::string transport_name_;
305 bool rtcp_transport_enabled_; 333 bool rtcp_transport_enabled_;
306 TransportChannel* transport_channel_; 334 TransportChannel* transport_channel_;
307 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_; 335 std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
308 TransportChannel* rtcp_transport_channel_; 336 TransportChannel* rtcp_transport_channel_;
309 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_; 337 std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
310 SrtpFilter srtp_filter_; 338 SrtpFilter srtp_filter_;
311 RtcpMuxFilter rtcp_mux_filter_; 339 RtcpMuxFilter rtcp_mux_filter_;
312 BundleFilter bundle_filter_; 340 BundleFilter bundle_filter_;
313 std::unique_ptr<ConnectionMonitor> connection_monitor_;
314 bool enabled_;
315 bool writable_;
316 bool rtp_ready_to_send_; 341 bool rtp_ready_to_send_;
317 bool rtcp_ready_to_send_; 342 bool rtcp_ready_to_send_;
343 bool writable_;
318 bool was_ever_writable_; 344 bool was_ever_writable_;
319 MediaContentDirection local_content_direction_;
320 MediaContentDirection remote_content_direction_;
321 bool has_received_packet_; 345 bool has_received_packet_;
322 bool dtls_keyed_; 346 bool dtls_keyed_;
323 bool secure_required_; 347 bool secure_required_;
324 int rtp_abs_sendtime_extn_id_; 348 int rtp_abs_sendtime_extn_id_;
349
350 // MediaChannel related members that should be access from worker thread.
351 MediaChannel* const media_channel_;
352 // Currently enabled_ flag accessed from signaling thread too, but it can
353 // be changed only when signaling thread does sunchronious call to worker
354 // thread, so it should be safe.
355 bool enabled_;
356 std::vector<StreamParams> local_streams_;
357 std::vector<StreamParams> remote_streams_;
358 MediaContentDirection local_content_direction_;
359 MediaContentDirection remote_content_direction_;
325 }; 360 };
326 361
327 // VoiceChannel is a specialization that adds support for early media, DTMF, 362 // VoiceChannel is a specialization that adds support for early media, DTMF,
328 // and input/output level monitoring. 363 // and input/output level monitoring.
329 class VoiceChannel : public BaseChannel { 364 class VoiceChannel : public BaseChannel {
330 public: 365 public:
331 VoiceChannel(rtc::Thread* thread, 366 VoiceChannel(rtc::Thread* worker_thread,
367 rtc::Thread* network_thread,
332 MediaEngineInterface* media_engine, 368 MediaEngineInterface* media_engine,
333 VoiceMediaChannel* channel, 369 VoiceMediaChannel* channel,
334 TransportController* transport_controller, 370 TransportController* transport_controller,
335 const std::string& content_name, 371 const std::string& content_name,
336 bool rtcp); 372 bool rtcp);
337 ~VoiceChannel(); 373 ~VoiceChannel();
338 bool Init(); 374 bool Init_w();
339 375
340 // Configure sending media on the stream with SSRC |ssrc| 376 // Configure sending media on the stream with SSRC |ssrc|
341 // If there is only one sending stream SSRC 0 can be used. 377 // If there is only one sending stream SSRC 0 can be used.
342 bool SetAudioSend(uint32_t ssrc, 378 bool SetAudioSend(uint32_t ssrc,
343 bool enable, 379 bool enable,
344 const AudioOptions* options, 380 const AudioOptions* options,
345 AudioSource* source); 381 AudioSource* source);
346 382
347 // downcasts a MediaChannel 383 // downcasts a MediaChannel
348 virtual VoiceMediaChannel* media_channel() const { 384 VoiceMediaChannel* media_channel() const override {
349 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel()); 385 return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
350 } 386 }
351 387
352 void SetEarlyMedia(bool enable); 388 void SetEarlyMedia(bool enable);
353 // This signal is emitted when we have gone a period of time without 389 // This signal is emitted when we have gone a period of time without
354 // receiving early media. When received, a UI should start playing its 390 // receiving early media. When received, a UI should start playing its
355 // own ringing sound 391 // own ringing sound
356 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout; 392 sigslot::signal1<VoiceChannel*> SignalEarlyMediaTimeout;
357 393
358 // Returns if the telephone-event has been negotiated. 394 // Returns if the telephone-event has been negotiated.
(...skipping 27 matching lines...) Expand all
386 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor; 422 sigslot::signal2<VoiceChannel*, const AudioInfo&> SignalAudioMonitor;
387 423
388 int GetInputLevel_w(); 424 int GetInputLevel_w();
389 int GetOutputLevel_w(); 425 int GetOutputLevel_w();
390 void GetActiveStreams_w(AudioInfo::StreamList* actives); 426 void GetActiveStreams_w(AudioInfo::StreamList* actives);
391 webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const; 427 webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const;
392 bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters); 428 bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
393 429
394 private: 430 private:
395 // overrides from BaseChannel 431 // overrides from BaseChannel
396 virtual void OnChannelRead(TransportChannel* channel, 432 void OnChannelRead(TransportChannel* channel,
397 const char* data, size_t len, 433 const char* data,
398 const rtc::PacketTime& packet_time, 434 size_t len,
399 int flags); 435 const rtc::PacketTime& packet_time,
400 virtual void ChangeState(); 436 int flags) override;
401 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); 437 void ChangeState_w() override;
402 virtual bool SetLocalContent_w(const MediaContentDescription* content, 438 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
403 ContentAction action, 439 bool SetLocalContent_w(const MediaContentDescription* content,
404 std::string* error_desc); 440 ContentAction action,
405 virtual bool SetRemoteContent_w(const MediaContentDescription* content, 441 std::string* error_desc) override;
406 ContentAction action, 442 bool SetRemoteContent_w(const MediaContentDescription* content,
407 std::string* error_desc); 443 ContentAction action,
444 std::string* error_desc) override;
408 void HandleEarlyMediaTimeout(); 445 void HandleEarlyMediaTimeout();
409 bool InsertDtmf_w(uint32_t ssrc, int event, int duration); 446 bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
410 bool SetOutputVolume_w(uint32_t ssrc, double volume); 447 bool SetOutputVolume_w(uint32_t ssrc, double volume);
411 bool GetStats_w(VoiceMediaInfo* stats); 448 bool GetStats_w(VoiceMediaInfo* stats);
412 449
413 virtual void OnMessage(rtc::Message* pmsg); 450 void OnMessage(rtc::Message* pmsg) override;
414 virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; 451 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
415 virtual void OnConnectionMonitorUpdate( 452 void OnConnectionMonitorUpdate(
416 ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); 453 ConnectionMonitor* monitor,
417 virtual void OnMediaMonitorUpdate( 454 const std::vector<ConnectionInfo>& infos) override;
418 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info); 455 void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
456 const VoiceMediaInfo& info);
419 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info); 457 void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
420 458
421 static const int kEarlyMediaTimeout = 1000; 459 static const int kEarlyMediaTimeout = 1000;
422 MediaEngineInterface* media_engine_; 460 MediaEngineInterface* media_engine_;
423 bool received_media_; 461 bool received_media_;
424 std::unique_ptr<VoiceMediaMonitor> media_monitor_; 462 std::unique_ptr<VoiceMediaMonitor> media_monitor_;
425 std::unique_ptr<AudioMonitor> audio_monitor_; 463 std::unique_ptr<AudioMonitor> audio_monitor_;
426 464
427 // Last AudioSendParameters sent down to the media_channel() via 465 // Last AudioSendParameters sent down to the media_channel() via
428 // SetSendParameters. 466 // SetSendParameters.
429 AudioSendParameters last_send_params_; 467 AudioSendParameters last_send_params_;
430 // Last AudioRecvParameters sent down to the media_channel() via 468 // Last AudioRecvParameters sent down to the media_channel() via
431 // SetRecvParameters. 469 // SetRecvParameters.
432 AudioRecvParameters last_recv_params_; 470 AudioRecvParameters last_recv_params_;
433 }; 471 };
434 472
435 // VideoChannel is a specialization for video. 473 // VideoChannel is a specialization for video.
436 class VideoChannel : public BaseChannel { 474 class VideoChannel : public BaseChannel {
437 public: 475 public:
438 VideoChannel(rtc::Thread* thread, 476 VideoChannel(rtc::Thread* worker_thread,
477 rtc::Thread* netwokr_thread,
439 VideoMediaChannel* channel, 478 VideoMediaChannel* channel,
440 TransportController* transport_controller, 479 TransportController* transport_controller,
441 const std::string& content_name, 480 const std::string& content_name,
442 bool rtcp); 481 bool rtcp);
443 ~VideoChannel(); 482 ~VideoChannel();
444 bool Init(); 483 bool Init_w();
445 484
446 // downcasts a MediaChannel 485 // downcasts a MediaChannel
447 virtual VideoMediaChannel* media_channel() const { 486 VideoMediaChannel* media_channel() const override {
448 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel()); 487 return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
449 } 488 }
450 489
451 bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink); 490 bool SetSink(uint32_t ssrc, rtc::VideoSinkInterface<VideoFrame>* sink);
452 // Register a source. The |ssrc| must correspond to a registered 491 // Register a source. The |ssrc| must correspond to a registered
453 // send stream. 492 // send stream.
454 void SetSource(uint32_t ssrc, 493 void SetSource(uint32_t ssrc,
455 rtc::VideoSourceInterface<cricket::VideoFrame>* source); 494 rtc::VideoSourceInterface<cricket::VideoFrame>* source);
456 // Get statistics about the current media session. 495 // Get statistics about the current media session.
457 bool GetStats(VideoMediaInfo* stats); 496 bool GetStats(VideoMediaInfo* stats);
458 497
459 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&> 498 sigslot::signal2<VideoChannel*, const std::vector<ConnectionInfo>&>
460 SignalConnectionMonitor; 499 SignalConnectionMonitor;
461 500
462 void StartMediaMonitor(int cms); 501 void StartMediaMonitor(int cms);
463 void StopMediaMonitor(); 502 void StopMediaMonitor();
464 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor; 503 sigslot::signal2<VideoChannel*, const VideoMediaInfo&> SignalMediaMonitor;
465 504
466 bool SetVideoSend(uint32_t ssrc, bool enable, const VideoOptions* options); 505 bool SetVideoSend(uint32_t ssrc, bool enable, const VideoOptions* options);
467 webrtc::RtpParameters GetRtpParameters(uint32_t ssrc) const; 506 webrtc::RtpParameters GetRtpParameters(uint32_t ssrc) const;
468 bool SetRtpParameters(uint32_t ssrc, const webrtc::RtpParameters& parameters); 507 bool SetRtpParameters(uint32_t ssrc, const webrtc::RtpParameters& parameters);
469 508
470 private: 509 private:
471 // overrides from BaseChannel 510 // overrides from BaseChannel
472 virtual void ChangeState(); 511 void ChangeState_w() override;
473 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); 512 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
474 virtual bool SetLocalContent_w(const MediaContentDescription* content, 513 bool SetLocalContent_w(const MediaContentDescription* content,
475 ContentAction action, 514 ContentAction action,
476 std::string* error_desc); 515 std::string* error_desc) override;
477 virtual bool SetRemoteContent_w(const MediaContentDescription* content, 516 bool SetRemoteContent_w(const MediaContentDescription* content,
478 ContentAction action, 517 ContentAction action,
479 std::string* error_desc); 518 std::string* error_desc) override;
480 bool GetStats_w(VideoMediaInfo* stats); 519 bool GetStats_w(VideoMediaInfo* stats);
481 webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const; 520 webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const;
482 bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters); 521 bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
483 522
484 virtual void OnMessage(rtc::Message* pmsg); 523 void OnMessage(rtc::Message* pmsg) override;
485 virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; 524 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
486 virtual void OnConnectionMonitorUpdate( 525 void OnConnectionMonitorUpdate(
487 ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); 526 ConnectionMonitor* monitor,
488 virtual void OnMediaMonitorUpdate( 527 const std::vector<ConnectionInfo>& infos) override;
489 VideoMediaChannel* media_channel, const VideoMediaInfo& info); 528 void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
529 const VideoMediaInfo& info);
490 530
491 std::unique_ptr<VideoMediaMonitor> media_monitor_; 531 std::unique_ptr<VideoMediaMonitor> media_monitor_;
492 532
493 // Last VideoSendParameters sent down to the media_channel() via 533 // Last VideoSendParameters sent down to the media_channel() via
494 // SetSendParameters. 534 // SetSendParameters.
495 VideoSendParameters last_send_params_; 535 VideoSendParameters last_send_params_;
496 // Last VideoRecvParameters sent down to the media_channel() via 536 // Last VideoRecvParameters sent down to the media_channel() via
497 // SetRecvParameters. 537 // SetRecvParameters.
498 VideoRecvParameters last_recv_params_; 538 VideoRecvParameters last_recv_params_;
499 }; 539 };
500 540
501 // DataChannel is a specialization for data. 541 // DataChannel is a specialization for data.
502 class DataChannel : public BaseChannel { 542 class DataChannel : public BaseChannel {
503 public: 543 public:
504 DataChannel(rtc::Thread* thread, 544 DataChannel(rtc::Thread* worker_thread,
545 rtc::Thread* network_thread,
505 DataMediaChannel* media_channel, 546 DataMediaChannel* media_channel,
506 TransportController* transport_controller, 547 TransportController* transport_controller,
507 const std::string& content_name, 548 const std::string& content_name,
508 bool rtcp); 549 bool rtcp);
509 ~DataChannel(); 550 ~DataChannel();
510 bool Init(); 551 bool Init_w();
511 552
512 virtual bool SendData(const SendDataParams& params, 553 virtual bool SendData(const SendDataParams& params,
513 const rtc::CopyOnWriteBuffer& payload, 554 const rtc::CopyOnWriteBuffer& payload,
514 SendDataResult* result); 555 SendDataResult* result);
515 556
516 void StartMediaMonitor(int cms); 557 void StartMediaMonitor(int cms);
517 void StopMediaMonitor(); 558 void StopMediaMonitor();
518 559
519 // Should be called on the signaling thread only. 560 // Should be called on the signaling thread only.
520 bool ready_to_send_data() const { 561 bool ready_to_send_data() const {
521 return ready_to_send_data_; 562 return ready_to_send_data_;
522 } 563 }
523 564
524 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor; 565 sigslot::signal2<DataChannel*, const DataMediaInfo&> SignalMediaMonitor;
525 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&> 566 sigslot::signal2<DataChannel*, const std::vector<ConnectionInfo>&>
526 SignalConnectionMonitor; 567 SignalConnectionMonitor;
527 sigslot::signal3<DataChannel*, const ReceiveDataParams&, 568 sigslot::signal3<DataChannel*, const ReceiveDataParams&,
528 const rtc::CopyOnWriteBuffer&> SignalDataReceived; 569 const rtc::CopyOnWriteBuffer&> SignalDataReceived;
529 // Signal for notifying when the channel becomes ready to send data. 570 // Signal for notifying when the channel becomes ready to send data.
530 // That occurs when the channel is enabled, the transport is writable, 571 // That occurs when the channel is enabled, the transport is writable,
531 // both local and remote descriptions are set, and the channel is unblocked. 572 // both local and remote descriptions are set, and the channel is unblocked.
532 sigslot::signal1<bool> SignalReadyToSendData; 573 sigslot::signal1<bool> SignalReadyToSendData;
533 // Signal for notifying that the remote side has closed the DataChannel. 574 // Signal for notifying that the remote side has closed the DataChannel.
534 sigslot::signal1<uint32_t> SignalStreamClosedRemotely; 575 sigslot::signal1<uint32_t> SignalStreamClosedRemotely;
535 576
536 protected: 577 protected:
537 // downcasts a MediaChannel. 578 // downcasts a MediaChannel.
538 virtual DataMediaChannel* media_channel() const { 579 DataMediaChannel* media_channel() const override {
539 return static_cast<DataMediaChannel*>(BaseChannel::media_channel()); 580 return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
540 } 581 }
541 582
542 private: 583 private:
543 struct SendDataMessageData : public rtc::MessageData { 584 struct SendDataMessageData : public rtc::MessageData {
544 SendDataMessageData(const SendDataParams& params, 585 SendDataMessageData(const SendDataParams& params,
545 const rtc::CopyOnWriteBuffer* payload, 586 const rtc::CopyOnWriteBuffer* payload,
546 SendDataResult* result) 587 SendDataResult* result)
547 : params(params), 588 : params(params),
548 payload(payload), 589 payload(payload),
(...skipping 16 matching lines...) Expand all
565 : params(params), 606 : params(params),
566 payload(data, len) { 607 payload(data, len) {
567 } 608 }
568 const ReceiveDataParams params; 609 const ReceiveDataParams params;
569 const rtc::CopyOnWriteBuffer payload; 610 const rtc::CopyOnWriteBuffer payload;
570 }; 611 };
571 612
572 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData; 613 typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
573 614
574 // overrides from BaseChannel 615 // overrides from BaseChannel
575 virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc); 616 const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
576 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that 617 // If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
577 // it's the same as what was set previously. Returns false if it's 618 // it's the same as what was set previously. Returns false if it's
578 // set to one type one type and changed to another type later. 619 // set to one type one type and changed to another type later.
579 bool SetDataChannelType(DataChannelType new_data_channel_type, 620 bool SetDataChannelType(DataChannelType new_data_channel_type,
580 std::string* error_desc); 621 std::string* error_desc);
581 // Same as SetDataChannelType, but extracts the type from the 622 // Same as SetDataChannelType, but extracts the type from the
582 // DataContentDescription. 623 // DataContentDescription.
583 bool SetDataChannelTypeFromContent(const DataContentDescription* content, 624 bool SetDataChannelTypeFromContent(const DataContentDescription* content,
584 std::string* error_desc); 625 std::string* error_desc);
585 virtual bool SetLocalContent_w(const MediaContentDescription* content, 626 bool SetLocalContent_w(const MediaContentDescription* content,
586 ContentAction action, 627 ContentAction action,
587 std::string* error_desc); 628 std::string* error_desc) override;
588 virtual bool SetRemoteContent_w(const MediaContentDescription* content, 629 bool SetRemoteContent_w(const MediaContentDescription* content,
589 ContentAction action, 630 ContentAction action,
590 std::string* error_desc); 631 std::string* error_desc) override;
591 virtual void ChangeState(); 632 void ChangeState_w() override;
592 virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet); 633 bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
593 634
594 virtual void OnMessage(rtc::Message* pmsg); 635 void OnMessage(rtc::Message* pmsg) override;
595 virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const; 636 void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
596 virtual void OnConnectionMonitorUpdate( 637 void OnConnectionMonitorUpdate(
597 ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos); 638 ConnectionMonitor* monitor,
598 virtual void OnMediaMonitorUpdate( 639 const std::vector<ConnectionInfo>& infos) override;
599 DataMediaChannel* media_channel, const DataMediaInfo& info); 640 void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
600 virtual bool ShouldSetupDtlsSrtp() const; 641 const DataMediaInfo& info);
642 bool ShouldSetupDtlsSrtp_n() const override;
601 void OnDataReceived( 643 void OnDataReceived(
602 const ReceiveDataParams& params, const char* data, size_t len); 644 const ReceiveDataParams& params, const char* data, size_t len);
603 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error); 645 void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
604 void OnDataChannelReadyToSend(bool writable); 646 void OnDataChannelReadyToSend(bool writable);
605 void OnStreamClosedRemotely(uint32_t sid); 647 void OnStreamClosedRemotely(uint32_t sid);
606 648
607 std::unique_ptr<DataMediaMonitor> media_monitor_; 649 std::unique_ptr<DataMediaMonitor> media_monitor_;
608 // TODO(pthatcher): Make a separate SctpDataChannel and 650 // TODO(pthatcher): Make a separate SctpDataChannel and
609 // RtpDataChannel instead of using this. 651 // RtpDataChannel instead of using this.
610 DataChannelType data_channel_type_; 652 DataChannelType data_channel_type_;
611 bool ready_to_send_data_; 653 bool ready_to_send_data_;
612 654
613 // Last DataSendParameters sent down to the media_channel() via 655 // Last DataSendParameters sent down to the media_channel() via
614 // SetSendParameters. 656 // SetSendParameters.
615 DataSendParameters last_send_params_; 657 DataSendParameters last_send_params_;
616 // Last DataRecvParameters sent down to the media_channel() via 658 // Last DataRecvParameters sent down to the media_channel() via
617 // SetRecvParameters. 659 // SetRecvParameters.
618 DataRecvParameters last_recv_params_; 660 DataRecvParameters last_recv_params_;
619 }; 661 };
620 662
621 } // namespace cricket 663 } // namespace cricket
622 664
623 #endif // WEBRTC_PC_CHANNEL_H_ 665 #endif // WEBRTC_PC_CHANNEL_H_
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/pc/channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698