Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: webrtc/pc/channel.cc

Issue 2437503004: Set actual transport overhead in rtp_rtcp (Closed)
Patch Set: Response to comments of honghaiz3 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 TransportController* transport_controller, 164 TransportController* transport_controller,
165 const std::string& content_name, 165 const std::string& content_name,
166 bool rtcp) 166 bool rtcp)
167 : worker_thread_(worker_thread), 167 : worker_thread_(worker_thread),
168 network_thread_(network_thread), 168 network_thread_(network_thread),
169 169
170 content_name_(content_name), 170 content_name_(content_name),
171 171
172 transport_controller_(transport_controller), 172 transport_controller_(transport_controller),
173 rtcp_enabled_(rtcp), 173 rtcp_enabled_(rtcp),
174 media_channel_(media_channel) { 174 media_channel_(media_channel),
175 selected_candidate_pair_(nullptr) {
175 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
176 if (transport_controller) { 177 if (transport_controller) {
177 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread()); 178 RTC_DCHECK_EQ(network_thread, transport_controller->network_thread());
178 } 179 }
179 LOG(LS_INFO) << "Created channel for " << content_name; 180 LOG(LS_INFO) << "Created channel for " << content_name;
180 } 181 }
181 182
182 BaseChannel::~BaseChannel() { 183 BaseChannel::~BaseChannel() {
183 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); 184 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel");
184 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 185 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 573 }
573 574
574 void BaseChannel::OnSelectedCandidatePairChanged( 575 void BaseChannel::OnSelectedCandidatePairChanged(
575 TransportChannel* channel, 576 TransportChannel* channel,
576 CandidatePairInterface* selected_candidate_pair, 577 CandidatePairInterface* selected_candidate_pair,
577 int last_sent_packet_id, 578 int last_sent_packet_id,
578 bool ready_to_send) { 579 bool ready_to_send) {
579 RTC_DCHECK(channel == transport_channel_ || 580 RTC_DCHECK(channel == transport_channel_ ||
580 channel == rtcp_transport_channel_); 581 channel == rtcp_transport_channel_);
581 RTC_DCHECK(network_thread_->IsCurrent()); 582 RTC_DCHECK(network_thread_->IsCurrent());
583 selected_candidate_pair_ = selected_candidate_pair;
582 std::string transport_name = channel->transport_name(); 584 std::string transport_name = channel->transport_name();
583 rtc::NetworkRoute network_route; 585 rtc::NetworkRoute network_route;
584 if (selected_candidate_pair) { 586 if (selected_candidate_pair) {
585 network_route = rtc::NetworkRoute( 587 network_route = rtc::NetworkRoute(
586 ready_to_send, selected_candidate_pair->local_candidate().network_id(), 588 ready_to_send, selected_candidate_pair->local_candidate().network_id(),
587 selected_candidate_pair->remote_candidate().network_id(), 589 selected_candidate_pair->remote_candidate().network_id(),
588 last_sent_packet_id); 590 last_sent_packet_id);
591
592 invoker_.AsyncInvoke<void>(
593 RTC_FROM_HERE, worker_thread_,
594 Bind(&MediaChannel::OnTransportOverheadChange, media_channel_,
595 GetTransportOverheadPerPacket()));
589 } 596 }
590 invoker_.AsyncInvoke<void>( 597 invoker_.AsyncInvoke<void>(
591 RTC_FROM_HERE, worker_thread_, 598 RTC_FROM_HERE, worker_thread_,
592 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, 599 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name,
593 network_route)); 600 network_route));
594 } 601 }
595 602
596 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { 603 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) {
597 RTC_DCHECK(network_thread_->IsCurrent()); 604 RTC_DCHECK(network_thread_->IsCurrent());
598 if (rtcp) { 605 if (rtcp) {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 static_cast<int>(send_key->size()), 1030 static_cast<int>(send_key->size()),
1024 selected_crypto_suite, &(*recv_key)[0], 1031 selected_crypto_suite, &(*recv_key)[0],
1025 static_cast<int>(recv_key->size())); 1032 static_cast<int>(recv_key->size()));
1026 } else { 1033 } else {
1027 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], 1034 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0],
1028 static_cast<int>(send_key->size()), 1035 static_cast<int>(send_key->size()),
1029 selected_crypto_suite, &(*recv_key)[0], 1036 selected_crypto_suite, &(*recv_key)[0],
1030 static_cast<int>(recv_key->size())); 1037 static_cast<int>(recv_key->size()));
1031 } 1038 }
1032 1039
1033 if (!ret) 1040 if (!ret) {
1034 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; 1041 LOG(LS_WARNING) << "DTLS-SRTP key installation failed";
1035 else 1042 } else {
1036 dtls_keyed_ = true; 1043 dtls_keyed_ = true;
1037 1044 invoker_.AsyncInvoke<void>(
1045 RTC_FROM_HERE, worker_thread_,
1046 Bind(&MediaChannel::OnTransportOverheadChange, media_channel_,
1047 GetTransportOverheadPerPacket()));
1048 }
1038 return ret; 1049 return ret;
1039 } 1050 }
1040 1051
1041 void BaseChannel::MaybeSetupDtlsSrtp_n() { 1052 void BaseChannel::MaybeSetupDtlsSrtp_n() {
1042 if (srtp_filter_.IsActive()) { 1053 if (srtp_filter_.IsActive()) {
1043 return; 1054 return;
1044 } 1055 }
1045 1056
1046 if (!ShouldSetupDtlsSrtp_n()) { 1057 if (!ShouldSetupDtlsSrtp_n()) {
1047 return; 1058 return;
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 } 1665 }
1655 } 1666 }
1656 1667
1657 void BaseChannel::UpdateMediaSendRecvState() { 1668 void BaseChannel::UpdateMediaSendRecvState() {
1658 RTC_DCHECK(network_thread_->IsCurrent()); 1669 RTC_DCHECK(network_thread_->IsCurrent());
1659 invoker_.AsyncInvoke<void>( 1670 invoker_.AsyncInvoke<void>(
1660 RTC_FROM_HERE, worker_thread_, 1671 RTC_FROM_HERE, worker_thread_,
1661 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); 1672 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this));
1662 } 1673 }
1663 1674
1675 int BaseChannel::GetTransportOverheadPerPacket() {
1676 RTC_DCHECK(network_thread_->IsCurrent());
1677
1678 if (!selected_candidate_pair_)
1679 return 0;
1680
1681 int transport_overhead_per_packet = 0;
1682
1683 constexpr int kIpv4Overhaed = 20;
1684 constexpr int kIpv6Overhaed = 40;
1685 transport_overhead_per_packet +=
1686 selected_candidate_pair_->local_candidate().address().family() == AF_INET
1687 ? kIpv4Overhaed
1688 : kIpv6Overhaed;
1689
1690 constexpr int kUdpOverhaed = 8;
1691 constexpr int kTcpOverhaed = 20;
1692 transport_overhead_per_packet +=
1693 selected_candidate_pair_->local_candidate().protocol() ==
1694 TCP_PROTOCOL_NAME
1695 ? kTcpOverhaed
1696 : kUdpOverhaed;
1697
1698 if (secure()) {
1699 int srtp_overhead = 0;
1700 if (srtp_filter_.GetSrtpOverhead(&srtp_overhead))
1701 transport_overhead_per_packet += srtp_overhead;
1702 }
1703
1704 return transport_overhead_per_packet;
1705 }
1706
1664 void VoiceChannel::UpdateMediaSendRecvState_w() { 1707 void VoiceChannel::UpdateMediaSendRecvState_w() {
1665 // Render incoming data if we're the active call, and we have the local 1708 // Render incoming data if we're the active call, and we have the local
1666 // content. We receive data on the default channel and multiplexed streams. 1709 // content. We receive data on the default channel and multiplexed streams.
1667 bool recv = IsReadyToReceiveMedia_w(); 1710 bool recv = IsReadyToReceiveMedia_w();
1668 media_channel()->SetPlayout(recv); 1711 media_channel()->SetPlayout(recv);
1669 1712
1670 // Send outgoing data if we're the active call, we have the remote content, 1713 // Send outgoing data if we're the active call, we have the remote content,
1671 // and we have had some form of connectivity. 1714 // and we have had some form of connectivity.
1672 bool send = IsReadyToSendMedia_w(); 1715 bool send = IsReadyToSendMedia_w();
1673 media_channel()->SetSend(send); 1716 media_channel()->SetSend(send);
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 } 2453 }
2411 2454
2412 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2455 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2413 rtc::TypedMessageData<uint32_t>* message = 2456 rtc::TypedMessageData<uint32_t>* message =
2414 new rtc::TypedMessageData<uint32_t>(sid); 2457 new rtc::TypedMessageData<uint32_t>(sid);
2415 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, 2458 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY,
2416 message); 2459 message);
2417 } 2460 }
2418 2461
2419 } // namespace cricket 2462 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698