| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 TransportController* transport_controller, | 165 TransportController* transport_controller, |
| 166 const std::string& content_name, | 166 const std::string& content_name, |
| 167 bool rtcp) | 167 bool rtcp) |
| 168 : worker_thread_(worker_thread), | 168 : worker_thread_(worker_thread), |
| 169 network_thread_(network_thread), | 169 network_thread_(network_thread), |
| 170 | 170 |
| 171 content_name_(content_name), | 171 content_name_(content_name), |
| 172 | 172 |
| 173 transport_controller_(transport_controller), | 173 transport_controller_(transport_controller), |
| 174 rtcp_enabled_(rtcp), | 174 rtcp_enabled_(rtcp), |
| 175 media_channel_(media_channel) { | 175 media_channel_(media_channel), |
| 176 selected_candidate_pair_(nullptr) { |
| 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 177 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 177 if (transport_controller) { | 178 if (transport_controller) { |
| 178 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); | 179 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); |
| 179 } | 180 } |
| 180 LOG(LS_INFO) << "Created channel for " << content_name; | 181 LOG(LS_INFO) << "Created channel for " << content_name; |
| 181 } | 182 } |
| 182 | 183 |
| 183 BaseChannel::~BaseChannel() { | 184 BaseChannel::~BaseChannel() { |
| 184 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 185 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
| 185 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 186 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | 382 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
| 382 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 383 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
| 383 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 384 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
| 384 tc->SignalSelectedCandidatePairChanged.connect( | 385 tc->SignalSelectedCandidatePairChanged.connect( |
| 385 this, &BaseChannel::OnSelectedCandidatePairChanged); | 386 this, &BaseChannel::OnSelectedCandidatePairChanged); |
| 386 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 387 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 387 } | 388 } |
| 388 | 389 |
| 389 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 390 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
| 390 RTC_DCHECK(network_thread_->IsCurrent()); | 391 RTC_DCHECK(network_thread_->IsCurrent()); |
| 392 OnSelectedCandidatePairChanged(tc, nullptr, -1, false); |
| 391 | 393 |
| 392 tc->SignalWritableState.disconnect(this); | 394 tc->SignalWritableState.disconnect(this); |
| 393 tc->SignalReadPacket.disconnect(this); | 395 tc->SignalReadPacket.disconnect(this); |
| 394 tc->SignalReadyToSend.disconnect(this); | 396 tc->SignalReadyToSend.disconnect(this); |
| 395 tc->SignalDtlsState.disconnect(this); | 397 tc->SignalDtlsState.disconnect(this); |
| 396 tc->SignalSelectedCandidatePairChanged.disconnect(this); | 398 tc->SignalSelectedCandidatePairChanged.disconnect(this); |
| 397 tc->SignalSentPacket.disconnect(this); | 399 tc->SignalSentPacket.disconnect(this); |
| 398 } | 400 } |
| 399 | 401 |
| 400 bool BaseChannel::Enable(bool enable) { | 402 bool BaseChannel::Enable(bool enable) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 } | 576 } |
| 575 | 577 |
| 576 void BaseChannel::OnSelectedCandidatePairChanged( | 578 void BaseChannel::OnSelectedCandidatePairChanged( |
| 577 TransportChannel* channel, | 579 TransportChannel* channel, |
| 578 CandidatePairInterface* selected_candidate_pair, | 580 CandidatePairInterface* selected_candidate_pair, |
| 579 int last_sent_packet_id, | 581 int last_sent_packet_id, |
| 580 bool ready_to_send) { | 582 bool ready_to_send) { |
| 581 RTC_DCHECK(channel == transport_channel_ || | 583 RTC_DCHECK(channel == transport_channel_ || |
| 582 channel == rtcp_transport_channel_); | 584 channel == rtcp_transport_channel_); |
| 583 RTC_DCHECK(network_thread_->IsCurrent()); | 585 RTC_DCHECK(network_thread_->IsCurrent()); |
| 586 selected_candidate_pair_ = selected_candidate_pair; |
| 584 std::string transport_name = channel->transport_name(); | 587 std::string transport_name = channel->transport_name(); |
| 585 rtc::NetworkRoute network_route; | 588 rtc::NetworkRoute network_route; |
| 586 if (selected_candidate_pair) { | 589 if (selected_candidate_pair) { |
| 587 network_route = rtc::NetworkRoute( | 590 network_route = rtc::NetworkRoute( |
| 588 ready_to_send, selected_candidate_pair->local_candidate().network_id(), | 591 ready_to_send, selected_candidate_pair->local_candidate().network_id(), |
| 589 selected_candidate_pair->remote_candidate().network_id(), | 592 selected_candidate_pair->remote_candidate().network_id(), |
| 590 last_sent_packet_id); | 593 last_sent_packet_id); |
| 594 |
| 595 UpdateTransportOverhead(); |
| 591 } | 596 } |
| 592 invoker_.AsyncInvoke<void>( | 597 invoker_.AsyncInvoke<void>( |
| 593 RTC_FROM_HERE, worker_thread_, | 598 RTC_FROM_HERE, worker_thread_, |
| 594 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, | 599 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, |
| 595 network_route)); | 600 network_route)); |
| 596 } | 601 } |
| 597 | 602 |
| 598 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { | 603 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { |
| 599 RTC_DCHECK(network_thread_->IsCurrent()); | 604 RTC_DCHECK(network_thread_->IsCurrent()); |
| 600 if (rtcp) { | 605 if (rtcp) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 | 903 |
| 899 void BaseChannel::ChannelWritable_n() { | 904 void BaseChannel::ChannelWritable_n() { |
| 900 RTC_DCHECK(network_thread_->IsCurrent()); | 905 RTC_DCHECK(network_thread_->IsCurrent()); |
| 901 if (writable_) { | 906 if (writable_) { |
| 902 return; | 907 return; |
| 903 } | 908 } |
| 904 | 909 |
| 905 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" | 910 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
| 906 << (was_ever_writable_ ? "" : " for the first time"); | 911 << (was_ever_writable_ ? "" : " for the first time"); |
| 907 | 912 |
| 908 std::vector<ConnectionInfo> infos; | 913 if (selected_candidate_pair_) |
| 909 transport_channel_->GetStats(&infos); | 914 LOG(LS_INFO) |
| 910 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 915 << "Using " |
| 911 it != infos.end(); ++it) { | 916 << selected_candidate_pair_->local_candidate().ToSensitiveString() |
| 912 if (it->best_connection) { | 917 << "->" |
| 913 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 918 << selected_candidate_pair_->remote_candidate().ToSensitiveString(); |
| 914 << "->" << it->remote_candidate.ToSensitiveString(); | |
| 915 break; | |
| 916 } | |
| 917 } | |
| 918 | 919 |
| 919 was_ever_writable_ = true; | 920 was_ever_writable_ = true; |
| 920 MaybeSetupDtlsSrtp_n(); | 921 MaybeSetupDtlsSrtp_n(); |
| 921 writable_ = true; | 922 writable_ = true; |
| 922 UpdateMediaSendRecvState(); | 923 UpdateMediaSendRecvState(); |
| 923 } | 924 } |
| 924 | 925 |
| 925 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) { | 926 void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) { |
| 926 RTC_DCHECK(network_thread_->IsCurrent()); | 927 RTC_DCHECK(network_thread_->IsCurrent()); |
| 927 invoker_.AsyncInvoke<void>( | 928 invoker_.AsyncInvoke<void>( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 static_cast<int>(send_key->size()), | 1027 static_cast<int>(send_key->size()), |
| 1027 selected_crypto_suite, &(*recv_key)[0], | 1028 selected_crypto_suite, &(*recv_key)[0], |
| 1028 static_cast<int>(recv_key->size())); | 1029 static_cast<int>(recv_key->size())); |
| 1029 } else { | 1030 } else { |
| 1030 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], | 1031 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], |
| 1031 static_cast<int>(send_key->size()), | 1032 static_cast<int>(send_key->size()), |
| 1032 selected_crypto_suite, &(*recv_key)[0], | 1033 selected_crypto_suite, &(*recv_key)[0], |
| 1033 static_cast<int>(recv_key->size())); | 1034 static_cast<int>(recv_key->size())); |
| 1034 } | 1035 } |
| 1035 | 1036 |
| 1036 if (!ret) | 1037 if (!ret) { |
| 1037 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; | 1038 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |
| 1038 else | 1039 } else { |
| 1039 dtls_keyed_ = true; | 1040 dtls_keyed_ = true; |
| 1040 | 1041 UpdateTransportOverhead(); |
| 1042 } |
| 1041 return ret; | 1043 return ret; |
| 1042 } | 1044 } |
| 1043 | 1045 |
| 1044 void BaseChannel::MaybeSetupDtlsSrtp_n() { | 1046 void BaseChannel::MaybeSetupDtlsSrtp_n() { |
| 1045 if (srtp_filter_.IsActive()) { | 1047 if (srtp_filter_.IsActive()) { |
| 1046 return; | 1048 return; |
| 1047 } | 1049 } |
| 1048 | 1050 |
| 1049 if (!ShouldSetupDtlsSrtp_n()) { | 1051 if (!ShouldSetupDtlsSrtp_n()) { |
| 1050 return; | 1052 return; |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 } | 1660 } |
| 1659 } | 1661 } |
| 1660 | 1662 |
| 1661 void BaseChannel::UpdateMediaSendRecvState() { | 1663 void BaseChannel::UpdateMediaSendRecvState() { |
| 1662 RTC_DCHECK(network_thread_->IsCurrent()); | 1664 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1663 invoker_.AsyncInvoke<void>( | 1665 invoker_.AsyncInvoke<void>( |
| 1664 RTC_FROM_HERE, worker_thread_, | 1666 RTC_FROM_HERE, worker_thread_, |
| 1665 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); | 1667 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); |
| 1666 } | 1668 } |
| 1667 | 1669 |
| 1670 int BaseChannel::GetTransportOverheadPerPacket() const { |
| 1671 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1672 |
| 1673 if (!selected_candidate_pair_) |
| 1674 return 0; |
| 1675 |
| 1676 int transport_overhead_per_packet = 0; |
| 1677 |
| 1678 constexpr int kIpv4Overhaed = 20; |
| 1679 constexpr int kIpv6Overhaed = 40; |
| 1680 transport_overhead_per_packet += |
| 1681 selected_candidate_pair_->local_candidate().address().family() == AF_INET |
| 1682 ? kIpv4Overhaed |
| 1683 : kIpv6Overhaed; |
| 1684 |
| 1685 constexpr int kUdpOverhaed = 8; |
| 1686 constexpr int kTcpOverhaed = 20; |
| 1687 transport_overhead_per_packet += |
| 1688 selected_candidate_pair_->local_candidate().protocol() == |
| 1689 TCP_PROTOCOL_NAME |
| 1690 ? kTcpOverhaed |
| 1691 : kUdpOverhaed; |
| 1692 |
| 1693 if (secure()) { |
| 1694 int srtp_overhead = 0; |
| 1695 if (srtp_filter_.GetSrtpOverhead(&srtp_overhead)) |
| 1696 transport_overhead_per_packet += srtp_overhead; |
| 1697 } |
| 1698 |
| 1699 return transport_overhead_per_packet; |
| 1700 } |
| 1701 |
| 1702 void BaseChannel::UpdateTransportOverhead() { |
| 1703 int transport_overhead_per_packet = GetTransportOverheadPerPacket(); |
| 1704 if (transport_overhead_per_packet) |
| 1705 invoker_.AsyncInvoke<void>( |
| 1706 RTC_FROM_HERE, worker_thread_, |
| 1707 Bind(&MediaChannel::OnTransportOverheadChanged, media_channel_, |
| 1708 transport_overhead_per_packet)); |
| 1709 } |
| 1710 |
| 1668 void VoiceChannel::UpdateMediaSendRecvState_w() { | 1711 void VoiceChannel::UpdateMediaSendRecvState_w() { |
| 1669 // Render incoming data if we're the active call, and we have the local | 1712 // Render incoming data if we're the active call, and we have the local |
| 1670 // content. We receive data on the default channel and multiplexed streams. | 1713 // content. We receive data on the default channel and multiplexed streams. |
| 1671 bool recv = IsReadyToReceiveMedia_w(); | 1714 bool recv = IsReadyToReceiveMedia_w(); |
| 1672 media_channel()->SetPlayout(recv); | 1715 media_channel()->SetPlayout(recv); |
| 1673 | 1716 |
| 1674 // Send outgoing data if we're the active call, we have the remote content, | 1717 // Send outgoing data if we're the active call, we have the remote content, |
| 1675 // and we have had some form of connectivity. | 1718 // and we have had some form of connectivity. |
| 1676 bool send = IsReadyToSendMedia_w(); | 1719 bool send = IsReadyToSendMedia_w(); |
| 1677 media_channel()->SetSend(send); | 1720 media_channel()->SetSend(send); |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2414 } | 2457 } |
| 2415 | 2458 |
| 2416 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2459 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2417 rtc::TypedMessageData<uint32_t>* message = | 2460 rtc::TypedMessageData<uint32_t>* message = |
| 2418 new rtc::TypedMessageData<uint32_t>(sid); | 2461 new rtc::TypedMessageData<uint32_t>(sid); |
| 2419 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, | 2462 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
| 2420 message); | 2463 message); |
| 2421 } | 2464 } |
| 2422 | 2465 |
| 2423 } // namespace cricket | 2466 } // namespace cricket |
| OLD | NEW |