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