Remove unnecessary thread hop for reporting transport stats
Bug: webrtc:12637 Change-Id: If00df716d30ac1db5faa83d2859f7c9787ad0ae9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213662 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33637}
This commit is contained in:

committed by
Commit Bot

parent
70b775d77f
commit
2001dc39db
@ -675,6 +675,9 @@ void PeerConnection::InitializeTransportController_n(
|
|||||||
transport_controller_->SubscribeIceConnectionState(
|
transport_controller_->SubscribeIceConnectionState(
|
||||||
[this](cricket::IceConnectionState s) {
|
[this](cricket::IceConnectionState s) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread());
|
RTC_DCHECK_RUN_ON(network_thread());
|
||||||
|
if (s == cricket::kIceConnectionConnected) {
|
||||||
|
ReportTransportStats();
|
||||||
|
}
|
||||||
signaling_thread()->PostTask(
|
signaling_thread()->PostTask(
|
||||||
ToQueuedTask(signaling_thread_safety_.flag(), [this, s]() {
|
ToQueuedTask(signaling_thread_safety_.flag(), [this, s]() {
|
||||||
RTC_DCHECK_RUN_ON(signaling_thread());
|
RTC_DCHECK_RUN_ON(signaling_thread());
|
||||||
@ -2277,8 +2280,8 @@ void PeerConnection::OnTransportControllerConnectionState(
|
|||||||
SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected);
|
SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected);
|
||||||
}
|
}
|
||||||
SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted);
|
SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted);
|
||||||
|
|
||||||
NoteUsageEvent(UsageEvent::ICE_STATE_CONNECTED);
|
NoteUsageEvent(UsageEvent::ICE_STATE_CONNECTED);
|
||||||
ReportTransportStats();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
RTC_NOTREACHED();
|
RTC_NOTREACHED();
|
||||||
@ -2638,6 +2641,7 @@ void PeerConnection::OnTransportControllerGatheringState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Runs on network_thread().
|
||||||
void PeerConnection::ReportTransportStats() {
|
void PeerConnection::ReportTransportStats() {
|
||||||
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
|
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
|
||||||
std::map<std::string, std::set<cricket::MediaType>>
|
std::map<std::string, std::set<cricket::MediaType>>
|
||||||
@ -2650,33 +2654,31 @@ void PeerConnection::ReportTransportStats() {
|
|||||||
transceiver->media_type());
|
transceiver->media_type());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtp_data_channel()) {
|
if (rtp_data_channel()) {
|
||||||
media_types_by_transport_name[rtp_data_channel()->transport_name()].insert(
|
media_types_by_transport_name[rtp_data_channel()->transport_name()].insert(
|
||||||
cricket::MEDIA_TYPE_DATA);
|
cricket::MEDIA_TYPE_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<std::string> transport_name = sctp_transport_name();
|
if (sctp_mid_n_) {
|
||||||
if (transport_name) {
|
auto dtls_transport = transport_controller_->GetDtlsTransport(*sctp_mid_n_);
|
||||||
media_types_by_transport_name[*transport_name].insert(
|
if (dtls_transport) {
|
||||||
cricket::MEDIA_TYPE_DATA);
|
media_types_by_transport_name[dtls_transport->transport_name()].insert(
|
||||||
|
cricket::MEDIA_TYPE_DATA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the loop that reports the state on the network thread since the
|
for (const auto& entry : media_types_by_transport_name) {
|
||||||
// transport controller requires the stats to be read there (GetStats()).
|
const std::string& transport_name = entry.first;
|
||||||
network_thread()->PostTask(ToQueuedTask(
|
const std::set<cricket::MediaType> media_types = entry.second;
|
||||||
network_thread_safety_, [this, media_types_by_transport_name = std::move(
|
cricket::TransportStats stats;
|
||||||
media_types_by_transport_name)] {
|
if (transport_controller_->GetStats(transport_name, &stats)) {
|
||||||
for (const auto& entry : media_types_by_transport_name) {
|
ReportBestConnectionState(stats);
|
||||||
const std::string& transport_name = entry.first;
|
ReportNegotiatedCiphers(dtls_enabled_, stats, media_types);
|
||||||
const std::set<cricket::MediaType> media_types = entry.second;
|
}
|
||||||
cricket::TransportStats stats;
|
}
|
||||||
if (transport_controller_->GetStats(transport_name, &stats)) {
|
|
||||||
ReportBestConnectionState(stats);
|
|
||||||
ReportNegotiatedCiphers(dtls_enabled_, stats, media_types);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk through the ConnectionInfos to gather best connection usage
|
// Walk through the ConnectionInfos to gather best connection usage
|
||||||
// for IPv4 and IPv6.
|
// for IPv4 and IPv6.
|
||||||
// static (no member state required)
|
// static (no member state required)
|
||||||
|
@ -577,7 +577,7 @@ class PeerConnection : public PeerConnectionInternal,
|
|||||||
|
|
||||||
// Invoked when TransportController connection completion is signaled.
|
// Invoked when TransportController connection completion is signaled.
|
||||||
// Reports stats for all transports in use.
|
// Reports stats for all transports in use.
|
||||||
void ReportTransportStats() RTC_RUN_ON(signaling_thread());
|
void ReportTransportStats() RTC_RUN_ON(network_thread());
|
||||||
|
|
||||||
// Gather the usage of IPv4/IPv6 as best connection.
|
// Gather the usage of IPv4/IPv6 as best connection.
|
||||||
static void ReportBestConnectionState(const cricket::TransportStats& stats);
|
static void ReportBestConnectionState(const cricket::TransportStats& stats);
|
||||||
|
Reference in New Issue
Block a user