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 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "webrtc/pc/channel.h" | 13 #include "webrtc/pc/channel.h" |
14 | 14 |
15 #include "webrtc/api/call/audio_sink.h" | 15 #include "webrtc/api/call/audio_sink.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/byteorder.h" | 17 #include "webrtc/base/byteorder.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/common.h" | 19 #include "webrtc/base/common.h" |
20 #include "webrtc/base/copyonwritebuffer.h" | 20 #include "webrtc/base/copyonwritebuffer.h" |
21 #include "webrtc/base/dscp.h" | 21 #include "webrtc/base/dscp.h" |
22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
23 #include "webrtc/base/networkroute.h" | 23 #include "webrtc/base/networkroute.h" |
24 #include "webrtc/base/trace_event.h" | 24 #include "webrtc/base/trace_event.h" |
25 #include "webrtc/media/base/mediaconstants.h" | 25 #include "webrtc/media/base/mediaconstants.h" |
26 #include "webrtc/media/base/rtputils.h" | 26 #include "webrtc/media/base/rtputils.h" |
27 #include "webrtc/p2p/base/packettransportinterface.h" | 27 #include "webrtc/p2p/base/packettransportinterface.h" |
| 28 #include "webrtc/p2p/base/transportchannel.h" |
28 #include "webrtc/pc/channelmanager.h" | 29 #include "webrtc/pc/channelmanager.h" |
29 | 30 |
30 namespace cricket { | 31 namespace cricket { |
31 using rtc::Bind; | 32 using rtc::Bind; |
32 | 33 |
33 namespace { | 34 namespace { |
34 // See comment below for why we need to use a pointer to a unique_ptr. | 35 // See comment below for why we need to use a pointer to a unique_ptr. |
35 bool SetRawAudioSink_w(VoiceMediaChannel* channel, | 36 bool SetRawAudioSink_w(VoiceMediaChannel* channel, |
36 uint32_t ssrc, | 37 uint32_t ssrc, |
37 std::unique_ptr<webrtc::AudioSinkInterface>* sink) { | 38 std::unique_ptr<webrtc::AudioSinkInterface>* sink) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 delete media_channel_; | 191 delete media_channel_; |
191 LOG(LS_INFO) << "Destroyed channel: " << content_name_; | 192 LOG(LS_INFO) << "Destroyed channel: " << content_name_; |
192 } | 193 } |
193 | 194 |
194 void BaseChannel::DisconnectTransportChannels_n() { | 195 void BaseChannel::DisconnectTransportChannels_n() { |
195 // Send any outstanding RTCP packets. | 196 // Send any outstanding RTCP packets. |
196 FlushRtcpMessages_n(); | 197 FlushRtcpMessages_n(); |
197 | 198 |
198 // Stop signals from transport channels, but keep them alive because | 199 // Stop signals from transport channels, but keep them alive because |
199 // media_channel may use them from a different thread. | 200 // media_channel may use them from a different thread. |
200 if (rtp_dtls_transport_) { | 201 if (rtp_transport_) { |
201 DisconnectFromTransport(rtp_dtls_transport_); | 202 DisconnectFromTransportChannel(rtp_transport_); |
202 } | 203 } |
203 if (rtcp_dtls_transport_) { | 204 if (rtcp_transport_) { |
204 DisconnectFromTransport(rtcp_dtls_transport_); | 205 DisconnectFromTransportChannel(rtcp_transport_); |
205 } | 206 } |
206 | 207 |
207 // Clear pending read packets/messages. | 208 // Clear pending read packets/messages. |
208 network_thread_->Clear(&invoker_); | 209 network_thread_->Clear(&invoker_); |
209 network_thread_->Clear(this); | 210 network_thread_->Clear(this); |
210 } | 211 } |
211 | 212 |
212 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 213 bool BaseChannel::Init_w(TransportChannel* rtp_transport, |
213 DtlsTransportInternal* rtcp_dtls_transport) { | 214 TransportChannel* rtcp_transport) { |
214 if (!network_thread_->Invoke<bool>( | 215 if (!network_thread_->Invoke<bool>( |
215 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this, | 216 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this, rtp_transport, |
216 rtp_dtls_transport, rtcp_dtls_transport))) { | 217 rtcp_transport))) { |
217 return false; | 218 return false; |
218 } | 219 } |
219 | 220 |
220 // Both RTP and RTCP channels are set, we can call SetInterface on | 221 // Both RTP and RTCP channels are set, we can call SetInterface on |
221 // media channel and it can set network options. | 222 // media channel and it can set network options. |
222 RTC_DCHECK(worker_thread_->IsCurrent()); | 223 RTC_DCHECK(worker_thread_->IsCurrent()); |
223 media_channel_->SetInterface(this); | 224 media_channel_->SetInterface(this); |
224 return true; | 225 return true; |
225 } | 226 } |
226 | 227 |
227 bool BaseChannel::InitNetwork_n(DtlsTransportInternal* rtp_dtls_transport, | 228 bool BaseChannel::InitNetwork_n(TransportChannel* rtp_transport, |
228 DtlsTransportInternal* rtcp_dtls_transport) { | 229 TransportChannel* rtcp_transport) { |
229 RTC_DCHECK(network_thread_->IsCurrent()); | 230 RTC_DCHECK(network_thread_->IsCurrent()); |
230 SetTransports_n(rtp_dtls_transport, rtcp_dtls_transport); | 231 SetTransports_n(rtp_transport, rtcp_transport); |
231 | 232 |
232 if (!SetDtlsSrtpCryptoSuites_n(rtp_dtls_transport_, false)) { | 233 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) { |
233 return false; | 234 return false; |
234 } | 235 } |
235 if (rtcp_dtls_transport_ && | 236 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) { |
236 !SetDtlsSrtpCryptoSuites_n(rtcp_dtls_transport_, true)) { | |
237 return false; | 237 return false; |
238 } | 238 } |
239 if (rtcp_mux_required_) { | 239 if (rtcp_mux_required_) { |
240 rtcp_mux_filter_.SetActive(); | 240 rtcp_mux_filter_.SetActive(); |
241 } | 241 } |
242 return true; | 242 return true; |
243 } | 243 } |
244 | 244 |
245 void BaseChannel::Deinit() { | 245 void BaseChannel::Deinit() { |
246 RTC_DCHECK(worker_thread_->IsCurrent()); | 246 RTC_DCHECK(worker_thread_->IsCurrent()); |
247 media_channel_->SetInterface(NULL); | 247 media_channel_->SetInterface(NULL); |
248 // Packets arrive on the network thread, processing packets calls virtual | 248 // Packets arrive on the network thread, processing packets calls virtual |
249 // functions, so need to stop this process in Deinit that is called in | 249 // functions, so need to stop this process in Deinit that is called in |
250 // derived classes destructor. | 250 // derived classes destructor. |
251 network_thread_->Invoke<void>( | 251 network_thread_->Invoke<void>( |
252 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); | 252 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); |
253 } | 253 } |
254 | 254 |
255 void BaseChannel::SetTransports(DtlsTransportInternal* rtp_dtls_transport, | 255 void BaseChannel::SetTransports(TransportChannel* rtp_transport, |
256 DtlsTransportInternal* rtcp_dtls_transport) { | 256 TransportChannel* rtcp_transport) { |
257 network_thread_->Invoke<void>(RTC_FROM_HERE, | 257 network_thread_->Invoke<void>( |
258 Bind(&BaseChannel::SetTransports_n, this, | 258 RTC_FROM_HERE, |
259 rtp_dtls_transport, rtcp_dtls_transport)); | 259 Bind(&BaseChannel::SetTransports_n, this, rtp_transport, rtcp_transport)); |
260 } | 260 } |
261 | 261 |
262 void BaseChannel::SetTransports_n(DtlsTransportInternal* rtp_dtls_transport, | 262 void BaseChannel::SetTransports_n(TransportChannel* rtp_transport, |
263 DtlsTransportInternal* rtcp_dtls_transport) { | 263 TransportChannel* rtcp_transport) { |
264 RTC_DCHECK(network_thread_->IsCurrent()); | 264 RTC_DCHECK(network_thread_->IsCurrent()); |
265 if (!rtp_dtls_transport && !rtcp_dtls_transport) { | 265 // Verify some assumptions (as described in the comment above SetTransport). |
266 LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport."; | 266 RTC_DCHECK(rtp_transport); |
267 return; | 267 RTC_DCHECK(NeedsRtcpTransport() == (rtcp_transport != nullptr)); |
| 268 if (rtcp_transport) { |
| 269 RTC_DCHECK(rtp_transport->transport_name() == |
| 270 rtcp_transport->transport_name()); |
268 } | 271 } |
269 | 272 |
270 if (rtcp_dtls_transport) { | 273 if (rtp_transport->transport_name() == transport_name_) { |
271 RTC_DCHECK(rtp_dtls_transport->transport_name() == | |
272 rtcp_dtls_transport->transport_name()); | |
273 RTC_DCHECK(NeedsRtcpTransport()); | |
274 } | |
275 | |
276 if (rtp_dtls_transport->transport_name() == transport_name_) { | |
277 // Nothing to do if transport name isn't changing. | 274 // Nothing to do if transport name isn't changing. |
278 return; | 275 return; |
279 } | 276 } |
280 | 277 |
281 transport_name_ = rtp_dtls_transport->transport_name(); | 278 transport_name_ = rtp_transport->transport_name(); |
282 | 279 |
283 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 280 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
284 // changes and wait until the DTLS handshake is complete to set the newly | 281 // changes and wait until the DTLS handshake is complete to set the newly |
285 // negotiated parameters. | 282 // negotiated parameters. |
286 if (ShouldSetupDtlsSrtp_n()) { | 283 if (ShouldSetupDtlsSrtp_n()) { |
287 // Set |writable_| to false such that UpdateWritableState_w can set up | 284 // Set |writable_| to false such that UpdateWritableState_w can set up |
288 // DTLS-SRTP when |writable_| becomes true again. | 285 // DTLS-SRTP when |writable_| becomes true again. |
289 writable_ = false; | 286 writable_ = false; |
290 srtp_filter_.ResetParams(); | 287 srtp_filter_.ResetParams(); |
291 } | 288 } |
292 | 289 |
293 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 290 // If this BaseChannel doesn't require RTCP mux and we haven't fully |
294 // negotiated RTCP mux, we need an RTCP transport. | 291 // negotiated RTCP mux, we need an RTCP transport. |
295 if (NeedsRtcpTransport()) { | 292 if (NeedsRtcpTransport()) { |
296 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " | 293 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " |
297 << transport_name() << " transport " << rtcp_dtls_transport; | 294 << transport_name() << " transport " << rtcp_transport; |
298 SetTransport_n(true, rtcp_dtls_transport); | 295 SetTransportChannel_n(true, rtcp_transport); |
299 RTC_DCHECK(rtcp_dtls_transport_); | 296 RTC_DCHECK(rtcp_transport_); |
300 } | 297 } |
301 | 298 |
302 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " | 299 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " |
303 << transport_name() << " transport " << rtp_dtls_transport; | 300 << transport_name() << " transport " << rtp_transport; |
304 SetTransport_n(false, rtp_dtls_transport); | 301 SetTransportChannel_n(false, rtp_transport); |
305 RTC_DCHECK(rtp_dtls_transport_); | 302 RTC_DCHECK(rtp_transport_); |
306 | 303 |
307 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 304 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
308 // setting new transport channels. | 305 // setting new transport channels. |
309 UpdateWritableState_n(); | 306 UpdateWritableState_n(); |
310 // We can only update ready-to-send after updating writability. | 307 // We can only update ready-to-send after updating writability. |
311 // | 308 // |
312 // On setting a new channel, assume it's ready to send if it's writable, | 309 // On setting a new channel, assume it's ready to send if it's writable, |
313 // because we have no way of knowing otherwise (the channel doesn't give us | 310 // because we have no way of knowing otherwise (the channel doesn't give us |
314 // "was last send successful?"). | 311 // "was last send successful?"). |
315 // | 312 // |
316 // This won't always be accurate (the last SendPacket call from another | 313 // This won't always be accurate (the last SendPacket call from another |
317 // BaseChannel could have resulted in an error), but even so, we'll just | 314 // BaseChannel could have resulted in an error), but even so, we'll just |
318 // encounter the error again and update "ready to send" accordingly. | 315 // encounter the error again and update "ready to send" accordingly. |
| 316 SetTransportChannelReadyToSend(false, |
| 317 rtp_transport_ && rtp_transport_->writable()); |
319 SetTransportChannelReadyToSend( | 318 SetTransportChannelReadyToSend( |
320 false, rtp_dtls_transport_ && rtp_dtls_transport_->writable()); | 319 true, rtcp_transport_ && rtcp_transport_->writable()); |
321 SetTransportChannelReadyToSend( | |
322 true, rtcp_dtls_transport_ && rtcp_dtls_transport_->writable()); | |
323 } | 320 } |
324 | 321 |
325 void BaseChannel::SetTransport_n(bool rtcp, | 322 void BaseChannel::SetTransportChannel_n(bool rtcp, |
326 DtlsTransportInternal* new_transport) { | 323 TransportChannel* new_transport) { |
327 RTC_DCHECK(network_thread_->IsCurrent()); | 324 RTC_DCHECK(network_thread_->IsCurrent()); |
328 DtlsTransportInternal*& old_transport = | 325 TransportChannel*& old_transport = rtcp ? rtcp_transport_ : rtp_transport_; |
329 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; | |
330 | |
331 if (!old_transport && !new_transport) { | 326 if (!old_transport && !new_transport) { |
332 // Nothing to do. | 327 // Nothing to do. |
333 return; | 328 return; |
334 } | 329 } |
335 | |
336 RTC_DCHECK(old_transport != new_transport); | 330 RTC_DCHECK(old_transport != new_transport); |
337 if (old_transport) { | 331 if (old_transport) { |
338 DisconnectFromTransport(old_transport); | 332 DisconnectFromTransportChannel(old_transport); |
339 } | 333 } |
340 | 334 |
341 old_transport = new_transport; | 335 old_transport = new_transport; |
342 | 336 |
343 if (new_transport) { | 337 if (new_transport) { |
344 if (rtcp) { | 338 if (rtcp) { |
345 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 339 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) |
346 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 340 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
347 << "should never happen."; | 341 << "should never happen."; |
348 } | 342 } |
349 ConnectToTransport(new_transport); | 343 ConnectToTransportChannel(new_transport); |
350 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; | 344 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; |
351 for (const auto& pair : socket_options) { | 345 for (const auto& pair : socket_options) { |
352 new_transport->SetOption(pair.first, pair.second); | 346 new_transport->SetOption(pair.first, pair.second); |
353 } | 347 } |
354 } | 348 } |
355 } | 349 } |
356 | 350 |
357 void BaseChannel::ConnectToTransport(DtlsTransportInternal* transport) { | 351 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
358 RTC_DCHECK(network_thread_->IsCurrent()); | 352 RTC_DCHECK(network_thread_->IsCurrent()); |
359 | 353 |
360 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 354 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
361 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | 355 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
362 transport->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 356 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
363 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 357 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
364 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 358 tc->SignalSelectedCandidatePairChanged.connect( |
365 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( | |
366 this, &BaseChannel::OnSelectedCandidatePairChanged); | 359 this, &BaseChannel::OnSelectedCandidatePairChanged); |
| 360 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
367 } | 361 } |
368 | 362 |
369 void BaseChannel::DisconnectFromTransport(DtlsTransportInternal* transport) { | 363 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
370 RTC_DCHECK(network_thread_->IsCurrent()); | 364 RTC_DCHECK(network_thread_->IsCurrent()); |
371 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, | 365 OnSelectedCandidatePairChanged(tc, nullptr, -1, false); |
372 false); | |
373 | 366 |
374 transport->SignalWritableState.disconnect(this); | 367 tc->SignalWritableState.disconnect(this); |
375 transport->SignalReadPacket.disconnect(this); | 368 tc->SignalReadPacket.disconnect(this); |
376 transport->SignalReadyToSend.disconnect(this); | 369 tc->SignalReadyToSend.disconnect(this); |
377 transport->SignalDtlsState.disconnect(this); | 370 tc->SignalDtlsState.disconnect(this); |
378 transport->SignalSentPacket.disconnect(this); | 371 tc->SignalSelectedCandidatePairChanged.disconnect(this); |
379 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( | 372 tc->SignalSentPacket.disconnect(this); |
380 this); | |
381 } | 373 } |
382 | 374 |
383 bool BaseChannel::Enable(bool enable) { | 375 bool BaseChannel::Enable(bool enable) { |
384 worker_thread_->Invoke<void>( | 376 worker_thread_->Invoke<void>( |
385 RTC_FROM_HERE, | 377 RTC_FROM_HERE, |
386 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 378 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
387 this)); | 379 this)); |
388 return true; | 380 return true; |
389 } | 381 } |
390 | 382 |
(...skipping 27 matching lines...) Expand all Loading... |
418 | 410 |
419 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, | 411 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, |
420 ContentAction action, | 412 ContentAction action, |
421 std::string* error_desc) { | 413 std::string* error_desc) { |
422 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); | 414 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); |
423 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, | 415 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, |
424 this, content, action, error_desc)); | 416 this, content, action, error_desc)); |
425 } | 417 } |
426 | 418 |
427 void BaseChannel::StartConnectionMonitor(int cms) { | 419 void BaseChannel::StartConnectionMonitor(int cms) { |
428 // We pass in the BaseChannel instead of the rtp_dtls_transport_ | 420 // We pass in the BaseChannel instead of the rtp_transport_ |
429 // because if the rtp_dtls_transport_ changes, the ConnectionMonitor | 421 // because if the rtp_transport_ changes, the ConnectionMonitor |
430 // would be pointing to the wrong TransportChannel. | 422 // would be pointing to the wrong TransportChannel. |
431 // We pass in the network thread because on that thread connection monitor | 423 // We pass in the network thread because on that thread connection monitor |
432 // will call BaseChannel::GetConnectionStats which must be called on the | 424 // will call BaseChannel::GetConnectionStats which must be called on the |
433 // network thread. | 425 // network thread. |
434 connection_monitor_.reset( | 426 connection_monitor_.reset( |
435 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); | 427 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); |
436 connection_monitor_->SignalUpdate.connect( | 428 connection_monitor_->SignalUpdate.connect( |
437 this, &BaseChannel::OnConnectionMonitorUpdate); | 429 this, &BaseChannel::OnConnectionMonitorUpdate); |
438 connection_monitor_->Start(cms); | 430 connection_monitor_->Start(cms); |
439 } | 431 } |
440 | 432 |
441 void BaseChannel::StopConnectionMonitor() { | 433 void BaseChannel::StopConnectionMonitor() { |
442 if (connection_monitor_) { | 434 if (connection_monitor_) { |
443 connection_monitor_->Stop(); | 435 connection_monitor_->Stop(); |
444 connection_monitor_.reset(); | 436 connection_monitor_.reset(); |
445 } | 437 } |
446 } | 438 } |
447 | 439 |
448 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { | 440 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |
449 RTC_DCHECK(network_thread_->IsCurrent()); | 441 RTC_DCHECK(network_thread_->IsCurrent()); |
450 return rtp_dtls_transport_->ice_transport()->GetStats(infos); | 442 return rtp_transport_->GetStats(infos); |
451 } | 443 } |
452 | 444 |
453 bool BaseChannel::NeedsRtcpTransport() { | 445 bool BaseChannel::NeedsRtcpTransport() { |
454 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 446 // If this BaseChannel doesn't require RTCP mux and we haven't fully |
455 // negotiated RTCP mux, we need an RTCP transport. | 447 // negotiated RTCP mux, we need an RTCP transport. |
456 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); | 448 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); |
457 } | 449 } |
458 | 450 |
459 bool BaseChannel::IsReadyToReceiveMedia_w() const { | 451 bool BaseChannel::IsReadyToReceiveMedia_w() const { |
460 // Receive data if we are enabled and have local content, | 452 // Receive data if we are enabled and have local content, |
(...skipping 28 matching lines...) Expand all Loading... |
489 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, | 481 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, |
490 int value) { | 482 int value) { |
491 return network_thread_->Invoke<int>( | 483 return network_thread_->Invoke<int>( |
492 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); | 484 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); |
493 } | 485 } |
494 | 486 |
495 int BaseChannel::SetOption_n(SocketType type, | 487 int BaseChannel::SetOption_n(SocketType type, |
496 rtc::Socket::Option opt, | 488 rtc::Socket::Option opt, |
497 int value) { | 489 int value) { |
498 RTC_DCHECK(network_thread_->IsCurrent()); | 490 RTC_DCHECK(network_thread_->IsCurrent()); |
499 DtlsTransportInternal* transport = nullptr; | 491 TransportChannel* channel = nullptr; |
500 switch (type) { | 492 switch (type) { |
501 case ST_RTP: | 493 case ST_RTP: |
502 transport = rtp_dtls_transport_; | 494 channel = rtp_transport_; |
503 socket_options_.push_back( | 495 socket_options_.push_back( |
504 std::pair<rtc::Socket::Option, int>(opt, value)); | 496 std::pair<rtc::Socket::Option, int>(opt, value)); |
505 break; | 497 break; |
506 case ST_RTCP: | 498 case ST_RTCP: |
507 transport = rtcp_dtls_transport_; | 499 channel = rtcp_transport_; |
508 rtcp_socket_options_.push_back( | 500 rtcp_socket_options_.push_back( |
509 std::pair<rtc::Socket::Option, int>(opt, value)); | 501 std::pair<rtc::Socket::Option, int>(opt, value)); |
510 break; | 502 break; |
511 } | 503 } |
512 return transport ? transport->ice_transport()->SetOption(opt, value) : -1; | 504 return channel ? channel->SetOption(opt, value) : -1; |
513 } | 505 } |
514 | 506 |
515 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { | 507 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
516 crypto_options_ = crypto_options; | 508 crypto_options_ = crypto_options; |
517 return true; | 509 return true; |
518 } | 510 } |
519 | 511 |
520 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { | 512 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { |
521 RTC_DCHECK(transport == rtp_dtls_transport_ || | 513 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); |
522 transport == rtcp_dtls_transport_); | |
523 RTC_DCHECK(network_thread_->IsCurrent()); | 514 RTC_DCHECK(network_thread_->IsCurrent()); |
524 UpdateWritableState_n(); | 515 UpdateWritableState_n(); |
525 } | 516 } |
526 | 517 |
527 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, | 518 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
528 const char* data, | 519 const char* data, |
529 size_t len, | 520 size_t len, |
530 const rtc::PacketTime& packet_time, | 521 const rtc::PacketTime& packet_time, |
531 int flags) { | 522 int flags) { |
532 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); | 523 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); |
533 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine | 524 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
534 RTC_DCHECK(network_thread_->IsCurrent()); | 525 RTC_DCHECK(network_thread_->IsCurrent()); |
535 | 526 |
536 // When using RTCP multiplexing we might get RTCP packets on the RTP | 527 // When using RTCP multiplexing we might get RTCP packets on the RTP |
537 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 528 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
538 bool rtcp = PacketIsRtcp(transport, data, len); | 529 bool rtcp = PacketIsRtcp(transport, data, len); |
539 rtc::CopyOnWriteBuffer packet(data, len); | 530 rtc::CopyOnWriteBuffer packet(data, len); |
540 HandlePacket(rtcp, &packet, packet_time); | 531 HandlePacket(rtcp, &packet, packet_time); |
541 } | 532 } |
542 | 533 |
543 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { | 534 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { |
544 RTC_DCHECK(transport == rtp_dtls_transport_ || | 535 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); |
545 transport == rtcp_dtls_transport_); | 536 SetTransportChannelReadyToSend(transport == rtcp_transport_, true); |
546 SetTransportChannelReadyToSend(transport == rtcp_dtls_transport_, true); | |
547 } | 537 } |
548 | 538 |
549 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, | 539 void BaseChannel::OnDtlsState(TransportChannel* channel, |
550 DtlsTransportState state) { | 540 DtlsTransportState state) { |
551 if (!ShouldSetupDtlsSrtp_n()) { | 541 if (!ShouldSetupDtlsSrtp_n()) { |
552 return; | 542 return; |
553 } | 543 } |
554 | 544 |
555 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 545 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
556 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 546 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
557 // cover other scenarios like the whole transport is writable (not just this | 547 // cover other scenarios like the whole channel is writable (not just this |
558 // TransportChannel) or when TransportChannel is attached after DTLS is | 548 // TransportChannel) or when TransportChannel is attached after DTLS is |
559 // negotiated. | 549 // negotiated. |
560 if (state != DTLS_TRANSPORT_CONNECTED) { | 550 if (state != DTLS_TRANSPORT_CONNECTED) { |
561 srtp_filter_.ResetParams(); | 551 srtp_filter_.ResetParams(); |
562 } | 552 } |
563 } | 553 } |
564 | 554 |
565 void BaseChannel::OnSelectedCandidatePairChanged( | 555 void BaseChannel::OnSelectedCandidatePairChanged( |
566 IceTransportInternal* ice_transport, | 556 TransportChannel* channel, |
567 CandidatePairInterface* selected_candidate_pair, | 557 CandidatePairInterface* selected_candidate_pair, |
568 int last_sent_packet_id, | 558 int last_sent_packet_id, |
569 bool ready_to_send) { | 559 bool ready_to_send) { |
570 RTC_DCHECK(ice_transport == rtp_dtls_transport_->ice_transport() || | 560 RTC_DCHECK(channel == rtp_transport_ || channel == rtcp_transport_); |
571 ice_transport == rtcp_dtls_transport_->ice_transport()); | |
572 RTC_DCHECK(network_thread_->IsCurrent()); | 561 RTC_DCHECK(network_thread_->IsCurrent()); |
573 selected_candidate_pair_ = selected_candidate_pair; | 562 selected_candidate_pair_ = selected_candidate_pair; |
574 std::string transport_name = ice_transport->transport_name(); | 563 std::string transport_name = channel->transport_name(); |
575 rtc::NetworkRoute network_route; | 564 rtc::NetworkRoute network_route; |
576 if (selected_candidate_pair) { | 565 if (selected_candidate_pair) { |
577 network_route = rtc::NetworkRoute( | 566 network_route = rtc::NetworkRoute( |
578 ready_to_send, selected_candidate_pair->local_candidate().network_id(), | 567 ready_to_send, selected_candidate_pair->local_candidate().network_id(), |
579 selected_candidate_pair->remote_candidate().network_id(), | 568 selected_candidate_pair->remote_candidate().network_id(), |
580 last_sent_packet_id); | 569 last_sent_packet_id); |
581 | 570 |
582 UpdateTransportOverhead(); | 571 UpdateTransportOverhead(); |
583 } | 572 } |
584 invoker_.AsyncInvoke<void>( | 573 invoker_.AsyncInvoke<void>( |
585 RTC_FROM_HERE, worker_thread_, | 574 RTC_FROM_HERE, worker_thread_, |
586 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, | 575 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, |
587 network_route)); | 576 network_route)); |
588 } | 577 } |
589 | 578 |
590 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { | 579 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { |
591 RTC_DCHECK(network_thread_->IsCurrent()); | 580 RTC_DCHECK(network_thread_->IsCurrent()); |
592 if (rtcp) { | 581 if (rtcp) { |
593 rtcp_ready_to_send_ = ready; | 582 rtcp_ready_to_send_ = ready; |
594 } else { | 583 } else { |
595 rtp_ready_to_send_ = ready; | 584 rtp_ready_to_send_ = ready; |
596 } | 585 } |
597 | 586 |
598 bool ready_to_send = | 587 bool ready_to_send = |
599 (rtp_ready_to_send_ && | 588 (rtp_ready_to_send_ && |
600 // In the case of rtcp mux |rtcp_dtls_transport_| will be null. | 589 // In the case of rtcp mux |rtcp_transport_| will be null. |
601 (rtcp_ready_to_send_ || !rtcp_dtls_transport_)); | 590 (rtcp_ready_to_send_ || !rtcp_transport_)); |
602 | 591 |
603 invoker_.AsyncInvoke<void>( | 592 invoker_.AsyncInvoke<void>( |
604 RTC_FROM_HERE, worker_thread_, | 593 RTC_FROM_HERE, worker_thread_, |
605 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 594 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); |
606 } | 595 } |
607 | 596 |
608 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, | 597 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, |
609 const char* data, | 598 const char* data, |
610 size_t len) { | 599 size_t len) { |
611 return (transport == rtcp_dtls_transport_ || | 600 return (transport == rtcp_transport_ || |
612 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 601 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
613 } | 602 } |
614 | 603 |
615 bool BaseChannel::SendPacket(bool rtcp, | 604 bool BaseChannel::SendPacket(bool rtcp, |
616 rtc::CopyOnWriteBuffer* packet, | 605 rtc::CopyOnWriteBuffer* packet, |
617 const rtc::PacketOptions& options) { | 606 const rtc::PacketOptions& options) { |
618 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 607 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. |
619 // If the thread is not our network thread, we will post to our network | 608 // If the thread is not our network thread, we will post to our network |
620 // so that the real work happens on our network. This avoids us having to | 609 // so that the real work happens on our network. This avoids us having to |
621 // synchronize access to all the pieces of the send path, including | 610 // synchronize access to all the pieces of the send path, including |
622 // SRTP and the inner workings of the transport channels. | 611 // SRTP and the inner workings of the transport channels. |
623 // The only downside is that we can't return a proper failure code if | 612 // The only downside is that we can't return a proper failure code if |
624 // needed. Since UDP is unreliable anyway, this should be a non-issue. | 613 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
625 if (!network_thread_->IsCurrent()) { | 614 if (!network_thread_->IsCurrent()) { |
626 // Avoid a copy by transferring the ownership of the packet data. | 615 // Avoid a copy by transferring the ownership of the packet data. |
627 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; | 616 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; |
628 SendPacketMessageData* data = new SendPacketMessageData; | 617 SendPacketMessageData* data = new SendPacketMessageData; |
629 data->packet = std::move(*packet); | 618 data->packet = std::move(*packet); |
630 data->options = options; | 619 data->options = options; |
631 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); | 620 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); |
632 return true; | 621 return true; |
633 } | 622 } |
634 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); | 623 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); |
635 | 624 |
636 // Now that we are on the correct thread, ensure we have a place to send this | 625 // Now that we are on the correct thread, ensure we have a place to send this |
637 // packet before doing anything. (We might get RTCP packets that we don't | 626 // packet before doing anything. (We might get RTCP packets that we don't |
638 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 627 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
639 // transport. | 628 // transport. |
640 DtlsTransportInternal* transport = (!rtcp || rtcp_mux_filter_.IsActive()) | 629 TransportChannel* channel = |
641 ? rtp_dtls_transport_ | 630 (!rtcp || rtcp_mux_filter_.IsActive()) ? rtp_transport_ : rtcp_transport_; |
642 : rtcp_dtls_transport_; | 631 if (!channel || !channel->writable()) { |
643 if (!transport || !transport->writable()) { | |
644 return false; | 632 return false; |
645 } | 633 } |
646 | 634 |
647 // Protect ourselves against crazy data. | 635 // Protect ourselves against crazy data. |
648 if (!ValidPacket(rtcp, packet)) { | 636 if (!ValidPacket(rtcp, packet)) { |
649 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 637 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
650 << PacketType(rtcp) | 638 << PacketType(rtcp) |
651 << " packet: wrong size=" << packet->size(); | 639 << " packet: wrong size=" << packet->size(); |
652 return false; | 640 return false; |
653 } | 641 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 // However, there shouldn't be any RTP packets sent before SRTP is set up | 712 // However, there shouldn't be any RTP packets sent before SRTP is set up |
725 // (and SetSend(true) is called). | 713 // (and SetSend(true) is called). |
726 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive" | 714 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive" |
727 << " and crypto is required"; | 715 << " and crypto is required"; |
728 RTC_NOTREACHED(); | 716 RTC_NOTREACHED(); |
729 return false; | 717 return false; |
730 } | 718 } |
731 | 719 |
732 // Bon voyage. | 720 // Bon voyage. |
733 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; | 721 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; |
734 int ret = transport->SendPacket(packet->data<char>(), packet->size(), | 722 int ret = channel->SendPacket(packet->data<char>(), packet->size(), |
735 updated_options, flags); | 723 updated_options, flags); |
736 if (ret != static_cast<int>(packet->size())) { | 724 if (ret != static_cast<int>(packet->size())) { |
737 if (transport->GetError() == ENOTCONN) { | 725 if (channel->GetError() == ENOTCONN) { |
738 LOG(LS_WARNING) << "Got ENOTCONN from transport."; | 726 LOG(LS_WARNING) << "Got ENOTCONN from transport."; |
739 SetTransportChannelReadyToSend(rtcp, false); | 727 SetTransportChannelReadyToSend(rtcp, false); |
740 } | 728 } |
741 return false; | 729 return false; |
742 } | 730 } |
743 return true; | 731 return true; |
744 } | 732 } |
745 | 733 |
746 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { | 734 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { |
747 // Protect ourselves against crazy data. | 735 // Protect ourselves against crazy data. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 790 } |
803 } | 791 } |
804 | 792 |
805 packet->SetSize(len); | 793 packet->SetSize(len); |
806 } else if (srtp_required_) { | 794 } else if (srtp_required_) { |
807 // Our session description indicates that SRTP is required, but we got a | 795 // Our session description indicates that SRTP is required, but we got a |
808 // packet before our SRTP filter is active. This means either that | 796 // packet before our SRTP filter is active. This means either that |
809 // a) we got SRTP packets before we received the SDES keys, in which case | 797 // a) we got SRTP packets before we received the SDES keys, in which case |
810 // we can't decrypt it anyway, or | 798 // we can't decrypt it anyway, or |
811 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP | 799 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP |
812 // transports, so we haven't yet extracted keys, even if DTLS did | 800 // channels, so we haven't yet extracted keys, even if DTLS did complete |
813 // complete on the transport that the packets are being sent on. It's | 801 // on the channel that the packets are being sent on. It's really good |
814 // really good practice to wait for both RTP and RTCP to be good to go | 802 // practice to wait for both RTP and RTCP to be good to go before sending |
815 // before sending media, to prevent weird failure modes, so it's fine | 803 // media, to prevent weird failure modes, so it's fine for us to just eat |
816 // for us to just eat packets here. This is all sidestepped if RTCP mux | 804 // packets here. This is all sidestepped if RTCP mux is used anyway. |
817 // is used anyway. | |
818 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) | 805 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) |
819 << " packet when SRTP is inactive and crypto is required"; | 806 << " packet when SRTP is inactive and crypto is required"; |
820 return; | 807 return; |
821 } | 808 } |
822 | 809 |
823 invoker_.AsyncInvoke<void>( | 810 invoker_.AsyncInvoke<void>( |
824 RTC_FROM_HERE, worker_thread_, | 811 RTC_FROM_HERE, worker_thread_, |
825 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); | 812 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); |
826 } | 813 } |
827 | 814 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 868 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
882 if (!enabled_) | 869 if (!enabled_) |
883 return; | 870 return; |
884 | 871 |
885 LOG(LS_INFO) << "Channel disabled"; | 872 LOG(LS_INFO) << "Channel disabled"; |
886 enabled_ = false; | 873 enabled_ = false; |
887 UpdateMediaSendRecvState_w(); | 874 UpdateMediaSendRecvState_w(); |
888 } | 875 } |
889 | 876 |
890 void BaseChannel::UpdateWritableState_n() { | 877 void BaseChannel::UpdateWritableState_n() { |
891 if (rtp_dtls_transport_ && rtp_dtls_transport_->writable() && | 878 if (rtp_transport_ && rtp_transport_->writable() && |
892 (!rtcp_dtls_transport_ || rtcp_dtls_transport_->writable())) { | 879 (!rtcp_transport_ || rtcp_transport_->writable())) { |
893 ChannelWritable_n(); | 880 ChannelWritable_n(); |
894 } else { | 881 } else { |
895 ChannelNotWritable_n(); | 882 ChannelNotWritable_n(); |
896 } | 883 } |
897 } | 884 } |
898 | 885 |
899 void BaseChannel::ChannelWritable_n() { | 886 void BaseChannel::ChannelWritable_n() { |
900 RTC_DCHECK(network_thread_->IsCurrent()); | 887 RTC_DCHECK(network_thread_->IsCurrent()); |
901 if (writable_) { | 888 if (writable_) { |
902 return; | 889 return; |
(...skipping 20 matching lines...) Expand all Loading... |
923 invoker_.AsyncInvoke<void>( | 910 invoker_.AsyncInvoke<void>( |
924 RTC_FROM_HERE, signaling_thread(), | 911 RTC_FROM_HERE, signaling_thread(), |
925 Bind(&BaseChannel::SignalDtlsSrtpSetupFailure_s, this, rtcp)); | 912 Bind(&BaseChannel::SignalDtlsSrtpSetupFailure_s, this, rtcp)); |
926 } | 913 } |
927 | 914 |
928 void BaseChannel::SignalDtlsSrtpSetupFailure_s(bool rtcp) { | 915 void BaseChannel::SignalDtlsSrtpSetupFailure_s(bool rtcp) { |
929 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); | 916 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); |
930 SignalDtlsSrtpSetupFailure(this, rtcp); | 917 SignalDtlsSrtpSetupFailure(this, rtcp); |
931 } | 918 } |
932 | 919 |
933 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(DtlsTransportInternal* transport, | 920 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { |
934 bool rtcp) { | |
935 std::vector<int> crypto_suites; | 921 std::vector<int> crypto_suites; |
936 // We always use the default SRTP crypto suites for RTCP, but we may use | 922 // We always use the default SRTP crypto suites for RTCP, but we may use |
937 // different crypto suites for RTP depending on the media type. | 923 // different crypto suites for RTP depending on the media type. |
938 if (!rtcp) { | 924 if (!rtcp) { |
939 GetSrtpCryptoSuites_n(&crypto_suites); | 925 GetSrtpCryptoSuites_n(&crypto_suites); |
940 } else { | 926 } else { |
941 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); | 927 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); |
942 } | 928 } |
943 return transport->SetSrtpCryptoSuites(crypto_suites); | 929 return tc->SetSrtpCryptoSuites(crypto_suites); |
944 } | 930 } |
945 | 931 |
946 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { | 932 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { |
947 // Since DTLS is applied to all transports, checking RTP should be enough. | 933 // Since DTLS is applied to all channels, checking RTP should be enough. |
948 return rtp_dtls_transport_ && rtp_dtls_transport_->IsDtlsActive(); | 934 return rtp_transport_ && rtp_transport_->IsDtlsActive(); |
949 } | 935 } |
950 | 936 |
951 // This function returns true if either DTLS-SRTP is not in use | 937 // This function returns true if either DTLS-SRTP is not in use |
952 // *or* DTLS-SRTP is successfully set up. | 938 // *or* DTLS-SRTP is successfully set up. |
953 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp) { | 939 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { |
954 RTC_DCHECK(network_thread_->IsCurrent()); | 940 RTC_DCHECK(network_thread_->IsCurrent()); |
955 bool ret = false; | 941 bool ret = false; |
956 | 942 |
957 DtlsTransportInternal* transport = | 943 TransportChannel* channel = rtcp_channel ? rtcp_transport_ : rtp_transport_; |
958 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; | |
959 | 944 |
960 RTC_DCHECK(transport->IsDtlsActive()); | 945 RTC_DCHECK(channel->IsDtlsActive()); |
961 | 946 |
962 int selected_crypto_suite; | 947 int selected_crypto_suite; |
963 | 948 |
964 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 949 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
965 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 950 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
966 return false; | 951 return false; |
967 } | 952 } |
968 | 953 |
969 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " " | 954 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " |
970 << PacketType(rtcp); | 955 << content_name() << " " |
| 956 << PacketType(rtcp_channel); |
971 | 957 |
972 int key_len; | 958 int key_len; |
973 int salt_len; | 959 int salt_len; |
974 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, | 960 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, |
975 &salt_len)) { | 961 &salt_len)) { |
976 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; | 962 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; |
977 return false; | 963 return false; |
978 } | 964 } |
979 | 965 |
980 // OK, we're now doing DTLS (RFC 5764) | 966 // OK, we're now doing DTLS (RFC 5764) |
981 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); | 967 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); |
982 | 968 |
983 // RFC 5705 exporter using the RFC 5764 parameters | 969 // RFC 5705 exporter using the RFC 5764 parameters |
984 if (!transport->ExportKeyingMaterial(kDtlsSrtpExporterLabel, NULL, 0, false, | 970 if (!channel->ExportKeyingMaterial( |
985 &dtls_buffer[0], dtls_buffer.size())) { | 971 kDtlsSrtpExporterLabel, |
| 972 NULL, 0, false, |
| 973 &dtls_buffer[0], dtls_buffer.size())) { |
986 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; | 974 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; |
987 RTC_NOTREACHED(); // This should never happen | 975 RTC_NOTREACHED(); // This should never happen |
988 return false; | 976 return false; |
989 } | 977 } |
990 | 978 |
991 // Sync up the keys with the DTLS-SRTP interface | 979 // Sync up the keys with the DTLS-SRTP interface |
992 std::vector<unsigned char> client_write_key(key_len + salt_len); | 980 std::vector<unsigned char> client_write_key(key_len + salt_len); |
993 std::vector<unsigned char> server_write_key(key_len + salt_len); | 981 std::vector<unsigned char> server_write_key(key_len + salt_len); |
994 size_t offset = 0; | 982 size_t offset = 0; |
995 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); | 983 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); |
996 offset += key_len; | 984 offset += key_len; |
997 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); | 985 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); |
998 offset += key_len; | 986 offset += key_len; |
999 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); | 987 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); |
1000 offset += salt_len; | 988 offset += salt_len; |
1001 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len); | 989 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len); |
1002 | 990 |
1003 std::vector<unsigned char> *send_key, *recv_key; | 991 std::vector<unsigned char> *send_key, *recv_key; |
1004 rtc::SSLRole role; | 992 rtc::SSLRole role; |
1005 if (!transport->GetSslRole(&role)) { | 993 if (!channel->GetSslRole(&role)) { |
1006 LOG(LS_WARNING) << "GetSslRole failed"; | 994 LOG(LS_WARNING) << "GetSslRole failed"; |
1007 return false; | 995 return false; |
1008 } | 996 } |
1009 | 997 |
1010 if (role == rtc::SSL_SERVER) { | 998 if (role == rtc::SSL_SERVER) { |
1011 send_key = &server_write_key; | 999 send_key = &server_write_key; |
1012 recv_key = &client_write_key; | 1000 recv_key = &client_write_key; |
1013 } else { | 1001 } else { |
1014 send_key = &client_write_key; | 1002 send_key = &client_write_key; |
1015 recv_key = &server_write_key; | 1003 recv_key = &server_write_key; |
1016 } | 1004 } |
1017 | 1005 |
1018 if (rtcp) { | 1006 if (rtcp_channel) { |
1019 ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0], | 1007 ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0], |
1020 static_cast<int>(send_key->size()), | 1008 static_cast<int>(send_key->size()), |
1021 selected_crypto_suite, &(*recv_key)[0], | 1009 selected_crypto_suite, &(*recv_key)[0], |
1022 static_cast<int>(recv_key->size())); | 1010 static_cast<int>(recv_key->size())); |
1023 } else { | 1011 } else { |
1024 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], | 1012 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], |
1025 static_cast<int>(send_key->size()), | 1013 static_cast<int>(send_key->size()), |
1026 selected_crypto_suite, &(*recv_key)[0], | 1014 selected_crypto_suite, &(*recv_key)[0], |
1027 static_cast<int>(recv_key->size())); | 1015 static_cast<int>(recv_key->size())); |
1028 } | 1016 } |
(...skipping 14 matching lines...) Expand all Loading... |
1043 | 1031 |
1044 if (!ShouldSetupDtlsSrtp_n()) { | 1032 if (!ShouldSetupDtlsSrtp_n()) { |
1045 return; | 1033 return; |
1046 } | 1034 } |
1047 | 1035 |
1048 if (!SetupDtlsSrtp_n(false)) { | 1036 if (!SetupDtlsSrtp_n(false)) { |
1049 SignalDtlsSrtpSetupFailure_n(false); | 1037 SignalDtlsSrtpSetupFailure_n(false); |
1050 return; | 1038 return; |
1051 } | 1039 } |
1052 | 1040 |
1053 if (rtcp_dtls_transport_) { | 1041 if (rtcp_transport_) { |
1054 if (!SetupDtlsSrtp_n(true)) { | 1042 if (!SetupDtlsSrtp_n(true)) { |
1055 SignalDtlsSrtpSetupFailure_n(true); | 1043 SignalDtlsSrtpSetupFailure_n(true); |
1056 return; | 1044 return; |
1057 } | 1045 } |
1058 } | 1046 } |
1059 } | 1047 } |
1060 | 1048 |
1061 void BaseChannel::ChannelNotWritable_n() { | 1049 void BaseChannel::ChannelNotWritable_n() { |
1062 RTC_DCHECK(network_thread_->IsCurrent()); | 1050 RTC_DCHECK(network_thread_->IsCurrent()); |
1063 if (!writable_) | 1051 if (!writable_) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 return false; | 1083 return false; |
1096 } | 1084 } |
1097 | 1085 |
1098 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { | 1086 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { |
1099 return false; | 1087 return false; |
1100 } | 1088 } |
1101 | 1089 |
1102 return true; | 1090 return true; |
1103 } | 1091 } |
1104 | 1092 |
1105 // |dtls| will be set to true if DTLS is active for transport and crypto is | 1093 // |dtls| will be set to true if DTLS is active for transport channel and |
1106 // empty. | 1094 // crypto is empty. |
1107 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, | 1095 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, |
1108 bool* dtls, | 1096 bool* dtls, |
1109 std::string* error_desc) { | 1097 std::string* error_desc) { |
1110 *dtls = rtp_dtls_transport_->IsDtlsActive(); | 1098 *dtls = rtp_transport_->IsDtlsActive(); |
1111 if (*dtls && !cryptos.empty()) { | 1099 if (*dtls && !cryptos.empty()) { |
1112 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); | 1100 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); |
1113 return false; | 1101 return false; |
1114 } | 1102 } |
1115 return true; | 1103 return true; |
1116 } | 1104 } |
1117 | 1105 |
1118 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, | 1106 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, |
1119 ContentAction action, | 1107 ContentAction action, |
1120 ContentSource src, | 1108 ContentSource src, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 "contain 'a=rtcp-mux'.", | 1162 "contain 'a=rtcp-mux'.", |
1175 error_desc); | 1163 error_desc); |
1176 return false; | 1164 return false; |
1177 } | 1165 } |
1178 bool ret = false; | 1166 bool ret = false; |
1179 switch (action) { | 1167 switch (action) { |
1180 case CA_OFFER: | 1168 case CA_OFFER: |
1181 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1169 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1182 break; | 1170 break; |
1183 case CA_PRANSWER: | 1171 case CA_PRANSWER: |
1184 // This may activate RTCP muxing, but we don't yet destroy the transport | 1172 // This may activate RTCP muxing, but we don't yet destroy the channel |
1185 // because the final answer may deactivate it. | 1173 // because the final answer may deactivate it. |
1186 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1174 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1187 break; | 1175 break; |
1188 case CA_ANSWER: | 1176 case CA_ANSWER: |
1189 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1177 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1190 if (ret && rtcp_mux_filter_.IsActive()) { | 1178 if (ret && rtcp_mux_filter_.IsActive()) { |
1191 // We activated RTCP mux, close down the RTCP transport. | 1179 // We activated RTCP mux, close down the RTCP transport. |
1192 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1180 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
1193 << " by destroying RTCP transport for " | 1181 << " by destroying RTCP transport channel for " |
1194 << transport_name(); | 1182 << transport_name(); |
1195 if (rtcp_dtls_transport()) { | 1183 if (rtcp_transport()) { |
1196 SetTransport_n(true, nullptr); | 1184 SetTransportChannel_n(true, nullptr); |
1197 SignalRtcpMuxFullyActive(rtp_dtls_transport()->transport_name()); | 1185 SignalRtcpMuxFullyActive(rtp_transport()->transport_name()); |
1198 } | 1186 } |
1199 UpdateWritableState_n(); | 1187 UpdateWritableState_n(); |
1200 SetTransportChannelReadyToSend(true, false); | 1188 SetTransportChannelReadyToSend(true, false); |
1201 } | 1189 } |
1202 break; | 1190 break; |
1203 case CA_UPDATE: | 1191 case CA_UPDATE: |
1204 // No RTCP mux info. | 1192 // No RTCP mux info. |
1205 ret = true; | 1193 ret = true; |
1206 break; | 1194 break; |
1207 default: | 1195 default: |
1208 break; | 1196 break; |
1209 } | 1197 } |
1210 if (!ret) { | 1198 if (!ret) { |
1211 SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 1199 SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
1212 return false; | 1200 return false; |
1213 } | 1201 } |
1214 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 1202 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |
1215 // CA_ANSWER, but we only want to tear down the RTCP transport if we received | 1203 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we |
1216 // a final answer. | 1204 // received a final answer. |
1217 if (rtcp_mux_filter_.IsActive()) { | 1205 if (rtcp_mux_filter_.IsActive()) { |
1218 // If the RTP transport is already writable, then so are we. | 1206 // If the RTP transport is already writable, then so are we. |
1219 if (rtp_dtls_transport_->writable()) { | 1207 if (rtp_transport_->writable()) { |
1220 ChannelWritable_n(); | 1208 ChannelWritable_n(); |
1221 } | 1209 } |
1222 } | 1210 } |
1223 | 1211 |
1224 return true; | 1212 return true; |
1225 } | 1213 } |
1226 | 1214 |
1227 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { | 1215 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |
1228 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); | 1216 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); |
1229 return media_channel()->AddRecvStream(sp); | 1217 return media_channel()->AddRecvStream(sp); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 | 1457 |
1470 VoiceChannel::~VoiceChannel() { | 1458 VoiceChannel::~VoiceChannel() { |
1471 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 1459 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |
1472 StopAudioMonitor(); | 1460 StopAudioMonitor(); |
1473 StopMediaMonitor(); | 1461 StopMediaMonitor(); |
1474 // this can't be done in the base class, since it calls a virtual | 1462 // this can't be done in the base class, since it calls a virtual |
1475 DisableMedia_w(); | 1463 DisableMedia_w(); |
1476 Deinit(); | 1464 Deinit(); |
1477 } | 1465 } |
1478 | 1466 |
1479 bool VoiceChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 1467 bool VoiceChannel::Init_w(TransportChannel* rtp_transport, |
1480 DtlsTransportInternal* rtcp_dtls_transport) { | 1468 TransportChannel* rtcp_transport) { |
1481 return BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport); | 1469 return BaseChannel::Init_w(rtp_transport, rtcp_transport); |
1482 } | 1470 } |
1483 | 1471 |
1484 bool VoiceChannel::SetAudioSend(uint32_t ssrc, | 1472 bool VoiceChannel::SetAudioSend(uint32_t ssrc, |
1485 bool enable, | 1473 bool enable, |
1486 const AudioOptions* options, | 1474 const AudioOptions* options, |
1487 AudioSource* source) { | 1475 AudioSource* source) { |
1488 return InvokeOnWorker(RTC_FROM_HERE, | 1476 return InvokeOnWorker(RTC_FROM_HERE, |
1489 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), | 1477 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), |
1490 ssrc, enable, options, source)); | 1478 ssrc, enable, options, source)); |
1491 } | 1479 } |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 bool rtcp_mux_required, | 1859 bool rtcp_mux_required, |
1872 bool srtp_required) | 1860 bool srtp_required) |
1873 : BaseChannel(worker_thread, | 1861 : BaseChannel(worker_thread, |
1874 network_thread, | 1862 network_thread, |
1875 signaling_thread, | 1863 signaling_thread, |
1876 media_channel, | 1864 media_channel, |
1877 content_name, | 1865 content_name, |
1878 rtcp_mux_required, | 1866 rtcp_mux_required, |
1879 srtp_required) {} | 1867 srtp_required) {} |
1880 | 1868 |
1881 bool VideoChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 1869 bool VideoChannel::Init_w(TransportChannel* rtp_transport, |
1882 DtlsTransportInternal* rtcp_dtls_transport) { | 1870 TransportChannel* rtcp_transport) { |
1883 return BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport); | 1871 return BaseChannel::Init_w(rtp_transport, rtcp_transport); |
1884 } | 1872 } |
1885 | 1873 |
1886 VideoChannel::~VideoChannel() { | 1874 VideoChannel::~VideoChannel() { |
1887 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); | 1875 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); |
1888 StopMediaMonitor(); | 1876 StopMediaMonitor(); |
1889 // this can't be done in the base class, since it calls a virtual | 1877 // this can't be done in the base class, since it calls a virtual |
1890 DisableMedia_w(); | 1878 DisableMedia_w(); |
1891 | 1879 |
1892 Deinit(); | 1880 Deinit(); |
1893 } | 1881 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2141 | 2129 |
2142 RtpDataChannel::~RtpDataChannel() { | 2130 RtpDataChannel::~RtpDataChannel() { |
2143 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); | 2131 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); |
2144 StopMediaMonitor(); | 2132 StopMediaMonitor(); |
2145 // this can't be done in the base class, since it calls a virtual | 2133 // this can't be done in the base class, since it calls a virtual |
2146 DisableMedia_w(); | 2134 DisableMedia_w(); |
2147 | 2135 |
2148 Deinit(); | 2136 Deinit(); |
2149 } | 2137 } |
2150 | 2138 |
2151 bool RtpDataChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 2139 bool RtpDataChannel::Init_w(TransportChannel* rtp_transport, |
2152 DtlsTransportInternal* rtcp_dtls_transport) { | 2140 TransportChannel* rtcp_transport) { |
2153 if (!BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport)) { | 2141 if (!BaseChannel::Init_w(rtp_transport, rtcp_transport)) { |
2154 return false; | 2142 return false; |
2155 } | 2143 } |
2156 media_channel()->SignalDataReceived.connect(this, | 2144 media_channel()->SignalDataReceived.connect(this, |
2157 &RtpDataChannel::OnDataReceived); | 2145 &RtpDataChannel::OnDataReceived); |
2158 media_channel()->SignalReadyToSend.connect( | 2146 media_channel()->SignalReadyToSend.connect( |
2159 this, &RtpDataChannel::OnDataChannelReadyToSend); | 2147 this, &RtpDataChannel::OnDataChannelReadyToSend); |
2160 return true; | 2148 return true; |
2161 } | 2149 } |
2162 | 2150 |
2163 bool RtpDataChannel::SendData(const SendDataParams& params, | 2151 bool RtpDataChannel::SendData(const SendDataParams& params, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2377 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2390 new DataChannelReadyToSendMessageData(writable)); | 2378 new DataChannelReadyToSendMessageData(writable)); |
2391 } | 2379 } |
2392 | 2380 |
2393 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2381 void RtpDataChannel::GetSrtpCryptoSuites_n( |
2394 std::vector<int>* crypto_suites) const { | 2382 std::vector<int>* crypto_suites) const { |
2395 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2383 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
2396 } | 2384 } |
2397 | 2385 |
2398 } // namespace cricket | 2386 } // namespace cricket |
OLD | NEW |