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