| 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 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 rtc::Thread* network_thread, | 161 rtc::Thread* network_thread, |
| 162 rtc::Thread* signaling_thread, | 162 rtc::Thread* signaling_thread, |
| 163 MediaChannel* media_channel, | 163 MediaChannel* media_channel, |
| 164 const std::string& content_name, | 164 const std::string& content_name, |
| 165 bool rtcp_mux_required, | 165 bool rtcp_mux_required, |
| 166 bool srtp_required) | 166 bool srtp_required) |
| 167 : worker_thread_(worker_thread), | 167 : worker_thread_(worker_thread), |
| 168 network_thread_(network_thread), | 168 network_thread_(network_thread), |
| 169 signaling_thread_(signaling_thread), | 169 signaling_thread_(signaling_thread), |
| 170 content_name_(content_name), | 170 content_name_(content_name), |
| 171 rtcp_mux_required_(rtcp_mux_required), |
| 171 rtp_transport_(rtcp_mux_required), | 172 rtp_transport_(rtcp_mux_required), |
| 172 srtp_required_(srtp_required), | 173 srtp_required_(srtp_required), |
| 173 media_channel_(media_channel), | 174 media_channel_(media_channel), |
| 174 selected_candidate_pair_(nullptr) { | 175 selected_candidate_pair_(nullptr) { |
| 175 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 176 #if defined(ENABLE_EXTERNAL_AUTH) | 177 #if defined(ENABLE_EXTERNAL_AUTH) |
| 177 srtp_filter_.EnableExternalAuth(); | 178 srtp_filter_.EnableExternalAuth(); |
| 178 #endif | 179 #endif |
| 180 rtp_transport_.SignalReadyToSend.connect( |
| 181 this, &BaseChannel::OnTransportReadyToSend); |
| 179 LOG(LS_INFO) << "Created channel for " << content_name; | 182 LOG(LS_INFO) << "Created channel for " << content_name; |
| 180 } | 183 } |
| 181 | 184 |
| 182 BaseChannel::~BaseChannel() { | 185 BaseChannel::~BaseChannel() { |
| 183 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 186 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
| 184 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 187 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 185 Deinit(); | 188 Deinit(); |
| 186 StopConnectionMonitor(); | 189 StopConnectionMonitor(); |
| 187 // Eats any outstanding messages or packets. | 190 // Eats any outstanding messages or packets. |
| 188 worker_thread_->Clear(&invoker_); | 191 worker_thread_->Clear(&invoker_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 238 |
| 236 bool BaseChannel::InitNetwork_n( | 239 bool BaseChannel::InitNetwork_n( |
| 237 DtlsTransportInternal* rtp_dtls_transport, | 240 DtlsTransportInternal* rtp_dtls_transport, |
| 238 DtlsTransportInternal* rtcp_dtls_transport, | 241 DtlsTransportInternal* rtcp_dtls_transport, |
| 239 rtc::PacketTransportInternal* rtp_packet_transport, | 242 rtc::PacketTransportInternal* rtp_packet_transport, |
| 240 rtc::PacketTransportInternal* rtcp_packet_transport) { | 243 rtc::PacketTransportInternal* rtcp_packet_transport) { |
| 241 RTC_DCHECK(network_thread_->IsCurrent()); | 244 RTC_DCHECK(network_thread_->IsCurrent()); |
| 242 SetTransports_n(rtp_dtls_transport, rtcp_dtls_transport, rtp_packet_transport, | 245 SetTransports_n(rtp_dtls_transport, rtcp_dtls_transport, rtp_packet_transport, |
| 243 rtcp_packet_transport); | 246 rtcp_packet_transport); |
| 244 | 247 |
| 245 if (rtp_transport_.rtcp_mux_required()) { | 248 if (rtcp_mux_required_) { |
| 246 rtcp_mux_filter_.SetActive(); | 249 rtcp_mux_filter_.SetActive(); |
| 247 } | 250 } |
| 248 return true; | 251 return true; |
| 249 } | 252 } |
| 250 | 253 |
| 251 void BaseChannel::Deinit() { | 254 void BaseChannel::Deinit() { |
| 252 RTC_DCHECK(worker_thread_->IsCurrent()); | 255 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 253 media_channel_->SetInterface(NULL); | 256 media_channel_->SetInterface(NULL); |
| 254 // Packets arrive on the network thread, processing packets calls virtual | 257 // Packets arrive on the network thread, processing packets calls virtual |
| 255 // functions, so need to stop this process in Deinit that is called in | 258 // functions, so need to stop this process in Deinit that is called in |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 SetTransport_n(true, rtcp_dtls_transport, rtcp_packet_transport); | 331 SetTransport_n(true, rtcp_dtls_transport, rtcp_packet_transport); |
| 329 } | 332 } |
| 330 | 333 |
| 331 LOG(LS_INFO) << "Setting RTP Transport for " << content_name() << " on " | 334 LOG(LS_INFO) << "Setting RTP Transport for " << content_name() << " on " |
| 332 << debug_name << " transport " << rtp_packet_transport; | 335 << debug_name << " transport " << rtp_packet_transport; |
| 333 SetTransport_n(false, rtp_dtls_transport, rtp_packet_transport); | 336 SetTransport_n(false, rtp_dtls_transport, rtp_packet_transport); |
| 334 | 337 |
| 335 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 338 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 336 // setting new transport channels. | 339 // setting new transport channels. |
| 337 UpdateWritableState_n(); | 340 UpdateWritableState_n(); |
| 338 // We can only update ready-to-send after updating writability. | |
| 339 // | |
| 340 // On setting a new channel, assume it's ready to send if it's writable, | |
| 341 // because we have no way of knowing otherwise (the channel doesn't give us | |
| 342 // "was last send successful?"). | |
| 343 // | |
| 344 // This won't always be accurate (the last SendPacket call from another | |
| 345 // BaseChannel could have resulted in an error), but even so, we'll just | |
| 346 // encounter the error again and update "ready to send" accordingly. | |
| 347 SetTransportChannelReadyToSend( | |
| 348 false, rtp_packet_transport && rtp_packet_transport->writable()); | |
| 349 SetTransportChannelReadyToSend( | |
| 350 true, rtcp_packet_transport && rtcp_packet_transport->writable()); | |
| 351 } | 341 } |
| 352 | 342 |
| 353 void BaseChannel::SetTransport_n( | 343 void BaseChannel::SetTransport_n( |
| 354 bool rtcp, | 344 bool rtcp, |
| 355 DtlsTransportInternal* new_dtls_transport, | 345 DtlsTransportInternal* new_dtls_transport, |
| 356 rtc::PacketTransportInternal* new_packet_transport) { | 346 rtc::PacketTransportInternal* new_packet_transport) { |
| 357 RTC_DCHECK(network_thread_->IsCurrent()); | 347 RTC_DCHECK(network_thread_->IsCurrent()); |
| 358 DtlsTransportInternal*& old_dtls_transport = | 348 DtlsTransportInternal*& old_dtls_transport = |
| 359 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; | 349 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; |
| 360 rtc::PacketTransportInternal* old_packet_transport = | 350 rtc::PacketTransportInternal* old_packet_transport = |
| 361 rtcp ? rtp_transport_.rtcp_packet_transport() | 351 rtcp ? rtp_transport_.rtcp_packet_transport() |
| 362 : rtp_transport_.rtp_packet_transport(); | 352 : rtp_transport_.rtp_packet_transport(); |
| 363 | 353 |
| 364 if (!old_packet_transport && !new_packet_transport) { | 354 if (!old_packet_transport && !new_packet_transport) { |
| 365 // Nothing to do. | 355 // Nothing to do. |
| 366 return; | 356 return; |
| 367 } | 357 } |
| 368 | 358 |
| 369 RTC_DCHECK(old_packet_transport != new_packet_transport); | 359 RTC_DCHECK(old_packet_transport != new_packet_transport); |
| 370 if (old_dtls_transport) { | 360 if (old_dtls_transport) { |
| 371 DisconnectFromDtlsTransport(old_dtls_transport); | 361 DisconnectFromDtlsTransport(old_dtls_transport); |
| 372 } else if (old_packet_transport) { | 362 } else if (old_packet_transport) { |
| 373 DisconnectFromPacketTransport(old_packet_transport); | 363 DisconnectFromPacketTransport(old_packet_transport); |
| 374 } | 364 } |
| 375 | 365 |
| 376 if (rtcp) { | 366 if (rtcp) { |
| 377 rtp_transport_.set_rtcp_packet_transport(new_packet_transport); | 367 rtp_transport_.SetRtcpPacketTransport(new_packet_transport); |
| 378 } else { | 368 } else { |
| 379 rtp_transport_.set_rtp_packet_transport(new_packet_transport); | 369 rtp_transport_.SetRtpPacketTransport(new_packet_transport); |
| 380 } | 370 } |
| 381 old_dtls_transport = new_dtls_transport; | 371 old_dtls_transport = new_dtls_transport; |
| 382 | 372 |
| 383 // If there's no new transport, we're done after disconnecting from old one. | 373 // If there's no new transport, we're done after disconnecting from old one. |
| 384 if (!new_packet_transport) { | 374 if (!new_packet_transport) { |
| 385 return; | 375 return; |
| 386 } | 376 } |
| 387 | 377 |
| 388 if (rtcp && new_dtls_transport) { | 378 if (rtcp && new_dtls_transport) { |
| 389 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 379 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) |
| 390 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 380 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
| 391 << "should never happen."; | 381 << "should never happen."; |
| 392 } | 382 } |
| 383 |
| 393 if (new_dtls_transport) { | 384 if (new_dtls_transport) { |
| 394 ConnectToDtlsTransport(new_dtls_transport); | 385 ConnectToDtlsTransport(new_dtls_transport); |
| 395 } else { | 386 } else { |
| 396 ConnectToPacketTransport(new_packet_transport); | 387 ConnectToPacketTransport(new_packet_transport); |
| 397 } | 388 } |
| 398 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; | 389 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; |
| 399 for (const auto& pair : socket_options) { | 390 for (const auto& pair : socket_options) { |
| 400 new_packet_transport->SetOption(pair.first, pair.second); | 391 new_packet_transport->SetOption(pair.first, pair.second); |
| 401 } | 392 } |
| 402 } | 393 } |
| 403 | 394 |
| 404 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) { | 395 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) { |
| 405 RTC_DCHECK(network_thread_->IsCurrent()); | 396 RTC_DCHECK(network_thread_->IsCurrent()); |
| 406 | 397 |
| 398 // TODO(zstein): de-dup with ConnectToPacketTransport |
| 407 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 399 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 408 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | 400 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
| 409 transport->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | |
| 410 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 401 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
| 411 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 402 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 412 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( | 403 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( |
| 413 this, &BaseChannel::OnSelectedCandidatePairChanged); | 404 this, &BaseChannel::OnSelectedCandidatePairChanged); |
| 414 } | 405 } |
| 415 | 406 |
| 416 void BaseChannel::DisconnectFromDtlsTransport( | 407 void BaseChannel::DisconnectFromDtlsTransport( |
| 417 DtlsTransportInternal* transport) { | 408 DtlsTransportInternal* transport) { |
| 418 RTC_DCHECK(network_thread_->IsCurrent()); | 409 RTC_DCHECK(network_thread_->IsCurrent()); |
| 419 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, | 410 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, |
| 420 false); | 411 false); |
| 421 | 412 |
| 422 transport->SignalWritableState.disconnect(this); | 413 transport->SignalWritableState.disconnect(this); |
| 423 transport->SignalReadPacket.disconnect(this); | 414 transport->SignalReadPacket.disconnect(this); |
| 424 transport->SignalReadyToSend.disconnect(this); | |
| 425 transport->SignalDtlsState.disconnect(this); | 415 transport->SignalDtlsState.disconnect(this); |
| 426 transport->SignalSentPacket.disconnect(this); | 416 transport->SignalSentPacket.disconnect(this); |
| 427 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( | 417 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( |
| 428 this); | 418 this); |
| 429 } | 419 } |
| 430 | 420 |
| 431 void BaseChannel::ConnectToPacketTransport( | 421 void BaseChannel::ConnectToPacketTransport( |
| 432 rtc::PacketTransportInternal* transport) { | 422 rtc::PacketTransportInternal* transport) { |
| 433 RTC_DCHECK_RUN_ON(network_thread_); | 423 RTC_DCHECK_RUN_ON(network_thread_); |
| 434 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 424 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 435 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | 425 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
| 436 transport->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | |
| 437 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 426 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 438 } | 427 } |
| 439 | 428 |
| 440 void BaseChannel::DisconnectFromPacketTransport( | 429 void BaseChannel::DisconnectFromPacketTransport( |
| 441 rtc::PacketTransportInternal* transport) { | 430 rtc::PacketTransportInternal* transport) { |
| 442 RTC_DCHECK_RUN_ON(network_thread_); | 431 RTC_DCHECK_RUN_ON(network_thread_); |
| 443 transport->SignalWritableState.disconnect(this); | 432 transport->SignalWritableState.disconnect(this); |
| 444 transport->SignalReadPacket.disconnect(this); | 433 transport->SignalReadPacket.disconnect(this); |
| 445 transport->SignalReadyToSend.disconnect(this); | |
| 446 transport->SignalSentPacket.disconnect(this); | 434 transport->SignalSentPacket.disconnect(this); |
| 447 } | 435 } |
| 448 | 436 |
| 449 bool BaseChannel::Enable(bool enable) { | 437 bool BaseChannel::Enable(bool enable) { |
| 450 worker_thread_->Invoke<void>( | 438 worker_thread_->Invoke<void>( |
| 451 RTC_FROM_HERE, | 439 RTC_FROM_HERE, |
| 452 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 440 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
| 453 this)); | 441 this)); |
| 454 return true; | 442 return true; |
| 455 } | 443 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 RTC_DCHECK(network_thread_->IsCurrent()); | 503 RTC_DCHECK(network_thread_->IsCurrent()); |
| 516 if (!rtp_dtls_transport_) { | 504 if (!rtp_dtls_transport_) { |
| 517 return false; | 505 return false; |
| 518 } | 506 } |
| 519 return rtp_dtls_transport_->ice_transport()->GetStats(infos); | 507 return rtp_dtls_transport_->ice_transport()->GetStats(infos); |
| 520 } | 508 } |
| 521 | 509 |
| 522 bool BaseChannel::NeedsRtcpTransport() { | 510 bool BaseChannel::NeedsRtcpTransport() { |
| 523 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 511 // If this BaseChannel doesn't require RTCP mux and we haven't fully |
| 524 // negotiated RTCP mux, we need an RTCP transport. | 512 // negotiated RTCP mux, we need an RTCP transport. |
| 525 return !rtp_transport_.rtcp_mux_required() && | 513 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); |
| 526 !rtcp_mux_filter_.IsFullyActive(); | |
| 527 } | 514 } |
| 528 | 515 |
| 529 bool BaseChannel::IsReadyToReceiveMedia_w() const { | 516 bool BaseChannel::IsReadyToReceiveMedia_w() const { |
| 530 // Receive data if we are enabled and have local content, | 517 // Receive data if we are enabled and have local content, |
| 531 return enabled() && IsReceiveContentDirection(local_content_direction_); | 518 return enabled() && IsReceiveContentDirection(local_content_direction_); |
| 532 } | 519 } |
| 533 | 520 |
| 534 bool BaseChannel::IsReadyToSendMedia_w() const { | 521 bool BaseChannel::IsReadyToSendMedia_w() const { |
| 535 // Need to access some state updated on the network thread. | 522 // Need to access some state updated on the network thread. |
| 536 return network_thread_->Invoke<bool>( | 523 return network_thread_->Invoke<bool>( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine | 585 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
| 599 RTC_DCHECK(network_thread_->IsCurrent()); | 586 RTC_DCHECK(network_thread_->IsCurrent()); |
| 600 | 587 |
| 601 // When using RTCP multiplexing we might get RTCP packets on the RTP | 588 // When using RTCP multiplexing we might get RTCP packets on the RTP |
| 602 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 589 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 603 bool rtcp = PacketIsRtcp(transport, data, len); | 590 bool rtcp = PacketIsRtcp(transport, data, len); |
| 604 rtc::CopyOnWriteBuffer packet(data, len); | 591 rtc::CopyOnWriteBuffer packet(data, len); |
| 605 HandlePacket(rtcp, &packet, packet_time); | 592 HandlePacket(rtcp, &packet, packet_time); |
| 606 } | 593 } |
| 607 | 594 |
| 608 void BaseChannel::OnReadyToSend(rtc::PacketTransportInternal* transport) { | |
| 609 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || | |
| 610 transport == rtp_transport_.rtcp_packet_transport()); | |
| 611 SetTransportChannelReadyToSend( | |
| 612 transport == rtp_transport_.rtcp_packet_transport(), true); | |
| 613 } | |
| 614 | |
| 615 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, | 595 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, |
| 616 DtlsTransportState state) { | 596 DtlsTransportState state) { |
| 617 if (!ShouldSetupDtlsSrtp_n()) { | 597 if (!ShouldSetupDtlsSrtp_n()) { |
| 618 return; | 598 return; |
| 619 } | 599 } |
| 620 | 600 |
| 621 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 601 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
| 622 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 602 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
| 623 // cover other scenarios like the whole transport is writable (not just this | 603 // cover other scenarios like the whole transport is writable (not just this |
| 624 // TransportChannel) or when TransportChannel is attached after DTLS is | 604 // TransportChannel) or when TransportChannel is attached after DTLS is |
| (...skipping 23 matching lines...) Expand all Loading... |
| 648 last_sent_packet_id); | 628 last_sent_packet_id); |
| 649 | 629 |
| 650 UpdateTransportOverhead(); | 630 UpdateTransportOverhead(); |
| 651 } | 631 } |
| 652 invoker_.AsyncInvoke<void>( | 632 invoker_.AsyncInvoke<void>( |
| 653 RTC_FROM_HERE, worker_thread_, | 633 RTC_FROM_HERE, worker_thread_, |
| 654 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, | 634 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, |
| 655 network_route)); | 635 network_route)); |
| 656 } | 636 } |
| 657 | 637 |
| 658 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { | 638 void BaseChannel::OnTransportReadyToSend(bool ready) { |
| 659 RTC_DCHECK(network_thread_->IsCurrent()); | |
| 660 if (rtcp) { | |
| 661 rtcp_ready_to_send_ = ready; | |
| 662 } else { | |
| 663 rtp_ready_to_send_ = ready; | |
| 664 } | |
| 665 | |
| 666 bool ready_to_send = | |
| 667 (rtp_ready_to_send_ && | |
| 668 // In the case of rtcp mux |rtcp_packet_transport_| will be null. | |
| 669 (rtcp_ready_to_send_ || !rtp_transport_.rtcp_packet_transport())); | |
| 670 | |
| 671 invoker_.AsyncInvoke<void>( | 639 invoker_.AsyncInvoke<void>( |
| 672 RTC_FROM_HERE, worker_thread_, | 640 RTC_FROM_HERE, worker_thread_, |
| 673 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 641 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready)); |
| 674 } | 642 } |
| 675 | 643 |
| 676 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInternal* transport, | 644 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
| 677 const char* data, | 645 const char* data, |
| 678 size_t len) { | 646 size_t len) { |
| 679 return (transport == rtp_transport_.rtcp_packet_transport() || | 647 return (transport == rtp_transport_.rtcp_packet_transport() || |
| 680 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 648 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 681 } | 649 } |
| 682 | 650 |
| 683 bool BaseChannel::SendPacket(bool rtcp, | 651 bool BaseChannel::SendPacket(bool rtcp, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 698 data->options = options; | 666 data->options = options; |
| 699 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); | 667 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); |
| 700 return true; | 668 return true; |
| 701 } | 669 } |
| 702 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); | 670 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); |
| 703 | 671 |
| 704 // Now that we are on the correct thread, ensure we have a place to send this | 672 // Now that we are on the correct thread, ensure we have a place to send this |
| 705 // packet before doing anything. (We might get RTCP packets that we don't | 673 // packet before doing anything. (We might get RTCP packets that we don't |
| 706 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 674 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
| 707 // transport. | 675 // transport. |
| 708 rtc::PacketTransportInternal* transport = | 676 if (!rtp_transport_.IsWritable(rtcp)) { |
| 709 (!rtcp || rtcp_mux_filter_.IsActive()) | |
| 710 ? rtp_transport_.rtp_packet_transport() | |
| 711 : rtp_transport_.rtcp_packet_transport(); | |
| 712 if (!transport || !transport->writable()) { | |
| 713 return false; | 677 return false; |
| 714 } | 678 } |
| 715 | 679 |
| 716 // Protect ourselves against crazy data. | 680 // Protect ourselves against crazy data. |
| 717 if (!ValidPacket(rtcp, packet)) { | 681 if (!ValidPacket(rtcp, packet)) { |
| 718 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 682 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
| 719 << PacketType(rtcp) | 683 << PacketType(rtcp) |
| 720 << " packet: wrong size=" << packet->size(); | 684 << " packet: wrong size=" << packet->size(); |
| 721 return false; | 685 return false; |
| 722 } | 686 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 // However, there shouldn't be any RTP packets sent before SRTP is set up | 762 // However, there shouldn't be any RTP packets sent before SRTP is set up |
| 799 // (and SetSend(true) is called). | 763 // (and SetSend(true) is called). |
| 800 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive" | 764 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive" |
| 801 << " and crypto is required"; | 765 << " and crypto is required"; |
| 802 RTC_NOTREACHED(); | 766 RTC_NOTREACHED(); |
| 803 return false; | 767 return false; |
| 804 } | 768 } |
| 805 | 769 |
| 806 // Bon voyage. | 770 // Bon voyage. |
| 807 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; | 771 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; |
| 808 int ret = transport->SendPacket(packet->data<char>(), packet->size(), | 772 return rtp_transport_.SendPacket(rtcp, packet, updated_options, flags); |
| 809 updated_options, flags); | |
| 810 if (ret != static_cast<int>(packet->size())) { | |
| 811 if (transport->GetError() == ENOTCONN) { | |
| 812 LOG(LS_WARNING) << "Got ENOTCONN from transport."; | |
| 813 SetTransportChannelReadyToSend(rtcp, false); | |
| 814 } | |
| 815 return false; | |
| 816 } | |
| 817 return true; | |
| 818 } | 773 } |
| 819 | 774 |
| 820 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { | 775 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { |
| 821 // Protect ourselves against crazy data. | 776 // Protect ourselves against crazy data. |
| 822 if (!ValidPacket(rtcp, packet)) { | 777 if (!ValidPacket(rtcp, packet)) { |
| 823 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " | 778 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " |
| 824 << PacketType(rtcp) | 779 << PacketType(rtcp) |
| 825 << " packet: wrong size=" << packet->size(); | 780 << " packet: wrong size=" << packet->size(); |
| 826 return false; | 781 return false; |
| 827 } | 782 } |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 } | 1181 } |
| 1227 return true; | 1182 return true; |
| 1228 } | 1183 } |
| 1229 | 1184 |
| 1230 bool BaseChannel::SetRtcpMux_n(bool enable, | 1185 bool BaseChannel::SetRtcpMux_n(bool enable, |
| 1231 ContentAction action, | 1186 ContentAction action, |
| 1232 ContentSource src, | 1187 ContentSource src, |
| 1233 std::string* error_desc) { | 1188 std::string* error_desc) { |
| 1234 // Provide a more specific error message for the RTCP mux "require" policy | 1189 // Provide a more specific error message for the RTCP mux "require" policy |
| 1235 // case. | 1190 // case. |
| 1236 if (rtp_transport_.rtcp_mux_required() && !enable) { | 1191 if (rtcp_mux_required_ && !enable) { |
| 1237 SafeSetError( | 1192 SafeSetError( |
| 1238 "rtcpMuxPolicy is 'require', but media description does not " | 1193 "rtcpMuxPolicy is 'require', but media description does not " |
| 1239 "contain 'a=rtcp-mux'.", | 1194 "contain 'a=rtcp-mux'.", |
| 1240 error_desc); | 1195 error_desc); |
| 1241 return false; | 1196 return false; |
| 1242 } | 1197 } |
| 1243 bool ret = false; | 1198 bool ret = false; |
| 1244 switch (action) { | 1199 switch (action) { |
| 1245 case CA_OFFER: | 1200 case CA_OFFER: |
| 1246 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1201 ret = rtcp_mux_filter_.SetOffer(enable, src); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1260 ? rtp_transport_.rtp_packet_transport()->debug_name() | 1215 ? rtp_transport_.rtp_packet_transport()->debug_name() |
| 1261 : transport_name_; | 1216 : transport_name_; |
| 1262 ; | 1217 ; |
| 1263 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1218 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
| 1264 << "; no longer need RTCP transport for " << debug_name; | 1219 << "; no longer need RTCP transport for " << debug_name; |
| 1265 if (rtp_transport_.rtcp_packet_transport()) { | 1220 if (rtp_transport_.rtcp_packet_transport()) { |
| 1266 SetTransport_n(true, nullptr, nullptr); | 1221 SetTransport_n(true, nullptr, nullptr); |
| 1267 SignalRtcpMuxFullyActive(transport_name_); | 1222 SignalRtcpMuxFullyActive(transport_name_); |
| 1268 } | 1223 } |
| 1269 UpdateWritableState_n(); | 1224 UpdateWritableState_n(); |
| 1270 SetTransportChannelReadyToSend(true, false); | |
| 1271 } | 1225 } |
| 1272 break; | 1226 break; |
| 1273 case CA_UPDATE: | 1227 case CA_UPDATE: |
| 1274 // No RTCP mux info. | 1228 // No RTCP mux info. |
| 1275 ret = true; | 1229 ret = true; |
| 1276 break; | 1230 break; |
| 1277 default: | 1231 default: |
| 1278 break; | 1232 break; |
| 1279 } | 1233 } |
| 1280 if (!ret) { | 1234 if (!ret) { |
| 1281 SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 1235 SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
| 1282 return false; | 1236 return false; |
| 1283 } | 1237 } |
| 1238 rtp_transport_.SetRtcpMuxEnabled(rtcp_mux_filter_.IsActive()); |
| 1284 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 1239 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |
| 1285 // CA_ANSWER, but we only want to tear down the RTCP transport if we received | 1240 // CA_ANSWER, but we only want to tear down the RTCP transport if we received |
| 1286 // a final answer. | 1241 // a final answer. |
| 1287 if (rtcp_mux_filter_.IsActive()) { | 1242 if (rtcp_mux_filter_.IsActive()) { |
| 1288 // If the RTP transport is already writable, then so are we. | 1243 // If the RTP transport is already writable, then so are we. |
| 1289 if (rtp_transport_.rtp_packet_transport()->writable()) { | 1244 if (rtp_transport_.rtp_packet_transport()->writable()) { |
| 1290 ChannelWritable_n(); | 1245 ChannelWritable_n(); |
| 1291 } | 1246 } |
| 1292 } | 1247 } |
| 1293 | 1248 |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2445 | 2400 |
| 2446 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { | 2401 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { |
| 2447 // This is usded for congestion control to indicate that the stream is ready | 2402 // This is usded for congestion control to indicate that the stream is ready |
| 2448 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 2403 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
| 2449 // that the transport channel is ready. | 2404 // that the transport channel is ready. |
| 2450 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2405 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
| 2451 new DataChannelReadyToSendMessageData(writable)); | 2406 new DataChannelReadyToSendMessageData(writable)); |
| 2452 } | 2407 } |
| 2453 | 2408 |
| 2454 } // namespace cricket | 2409 } // namespace cricket |
| OLD | NEW |