Reland "Implement packets_(sent | received) for RTCTransportStats"
This is a reland of fb6f975401972635a644c0db06c135b4c0aaef4a. Related
issue in chromium is fixed here:
https://chromium-review.googlesource.com/c/chromium/src/+/2287294
Original change's description:
> Implement packets_(sent | received) for RTCTransportStats
>
> Bug: webrtc:11756
> Change-Id: Ic0caad6d4675969ef3ae886f50326e4a2e1cbfe7
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178741
> Reviewed-by: Tommi <tommi@webrtc.org>
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Artem Titov <titovartem@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31643}
Bug: webrtc:11756
Change-Id: I1e310e3d23248500eb7dabd23d0ce6c4ec4cb8c6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178871
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31700}
diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h
index dc91f41..7d8f5f5 100644
--- a/api/stats/rtcstats_objects.h
+++ b/api/stats/rtcstats_objects.h
@@ -619,7 +619,9 @@
~RTCTransportStats() override;
RTCStatsMember<uint64_t> bytes_sent;
+ RTCStatsMember<uint64_t> packets_sent;
RTCStatsMember<uint64_t> bytes_received;
+ RTCStatsMember<uint64_t> packets_received;
RTCStatsMember<std::string> rtcp_transport_stats_id;
// TODO(hbos): Support enum types? "RTCStatsMember<RTCDtlsTransportState>"?
RTCStatsMember<std::string> dtls_state;
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc
index afb1457..0863865 100644
--- a/p2p/base/connection.cc
+++ b/p2p/base/connection.cc
@@ -461,6 +461,7 @@
last_data_received_ = rtc::TimeMillis();
UpdateReceiving(last_data_received_);
recv_rate_tracker_.AddSamples(size);
+ stats_.packets_received++;
SignalReadPacket(this, data, size, packet_time_us);
// If timed out sending writability checks, start up again
diff --git a/p2p/base/connection_info.cc b/p2p/base/connection_info.cc
index a4f8036..ebea2ab 100644
--- a/p2p/base/connection_info.cc
+++ b/p2p/base/connection_info.cc
@@ -28,6 +28,7 @@
sent_ping_responses(0),
recv_total_bytes(0),
recv_bytes_second(0),
+ packets_received(0),
recv_ping_requests(0),
recv_ping_responses(0),
key(nullptr),
diff --git a/p2p/base/connection_info.h b/p2p/base/connection_info.h
index a62e8ae..b5e1c14 100644
--- a/p2p/base/connection_info.h
+++ b/p2p/base/connection_info.h
@@ -54,6 +54,7 @@
size_t recv_total_bytes; // Total bytes received on this connection.
size_t recv_bytes_second; // Bps over the last measurement interval.
+ size_t packets_received; // Number of packets that were received.
size_t recv_ping_requests; // Number of STUN ping request received.
size_t recv_ping_responses; // Number of STUN ping response received.
Candidate local_candidate; // The local candidate for this connection.
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc
index 523e9e8..cfdee81 100644
--- a/p2p/base/p2p_transport_channel_unittest.cc
+++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -1284,6 +1284,7 @@
ep2_ch1()->receiving() &&
ep2_ch1()->writable(),
kMediumTimeout, clock);
+ // Sends and receives 10 packets.
TestSendRecv(&clock);
IceTransportStats ice_transport_stats;
ASSERT_TRUE(ep1_ch1()->GetStats(&ice_transport_stats));
@@ -1306,6 +1307,7 @@
EXPECT_EQ(0U, best_conn_info->sent_discarded_packets);
EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes);
EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
+ EXPECT_EQ(10U, best_conn_info->packets_received);
DestroyChannels();
}
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index be0bbd6..5851b06 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -1812,7 +1812,9 @@
transport_name, channel_stats.component),
timestamp_us));
transport_stats->bytes_sent = 0;
+ transport_stats->packets_sent = 0;
transport_stats->bytes_received = 0;
+ transport_stats->packets_received = 0;
transport_stats->dtls_state =
DtlsTransportStateToRTCDtlsTransportState(channel_stats.dtls_state);
transport_stats->selected_candidate_pair_changes =
@@ -1820,7 +1822,10 @@
for (const cricket::ConnectionInfo& info :
channel_stats.ice_transport_stats.connection_infos) {
*transport_stats->bytes_sent += info.sent_total_bytes;
+ *transport_stats->packets_sent +=
+ info.sent_total_packets - info.sent_discarded_packets;
*transport_stats->bytes_received += info.recv_total_bytes;
+ *transport_stats->packets_received += info.packets_received;
if (info.best_connection) {
transport_stats->selected_candidate_pair_id =
RTCIceCandidatePairStatsIDFromConnectionInfo(info);
diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc
index af9e545..becf735 100644
--- a/pc/rtc_stats_collector_unittest.cc
+++ b/pc/rtc_stats_collector_unittest.cc
@@ -2171,6 +2171,9 @@
rtp_connection_info.remote_candidate = *rtp_remote_candidate.get();
rtp_connection_info.sent_total_bytes = 42;
rtp_connection_info.recv_total_bytes = 1337;
+ rtp_connection_info.sent_total_packets = 3;
+ rtp_connection_info.sent_discarded_packets = 2;
+ rtp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtp_transport_channel_stats;
rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
rtp_transport_channel_stats.ice_transport_stats.connection_infos.push_back(
@@ -2188,7 +2191,9 @@
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTP),
report->timestamp_us());
expected_rtp_transport.bytes_sent = 42;
+ expected_rtp_transport.packets_sent = 1;
expected_rtp_transport.bytes_received = 1337;
+ expected_rtp_transport.packets_received = 4;
expected_rtp_transport.dtls_state = RTCDtlsTransportState::kNew;
expected_rtp_transport.selected_candidate_pair_changes = 1;
@@ -2203,6 +2208,9 @@
rtcp_connection_info.remote_candidate = *rtcp_remote_candidate.get();
rtcp_connection_info.sent_total_bytes = 1337;
rtcp_connection_info.recv_total_bytes = 42;
+ rtcp_connection_info.sent_total_packets = 3;
+ rtcp_connection_info.sent_discarded_packets = 2;
+ rtcp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtcp_transport_channel_stats;
rtcp_transport_channel_stats.component =
cricket::ICE_CANDIDATE_COMPONENT_RTCP;
@@ -2220,7 +2228,9 @@
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTCP),
report->timestamp_us());
expected_rtcp_transport.bytes_sent = 1337;
+ expected_rtcp_transport.packets_sent = 1;
expected_rtcp_transport.bytes_received = 42;
+ expected_rtcp_transport.packets_received = 4;
expected_rtcp_transport.dtls_state = RTCDtlsTransportState::kConnecting;
expected_rtcp_transport.selected_candidate_pair_changes = 0;
@@ -2314,6 +2324,9 @@
rtp_connection_info.remote_candidate = *rtp_remote_candidate.get();
rtp_connection_info.sent_total_bytes = 42;
rtp_connection_info.recv_total_bytes = 1337;
+ rtp_connection_info.sent_total_packets = 3;
+ rtp_connection_info.sent_discarded_packets = 2;
+ rtp_connection_info.packets_received = 4;
cricket::TransportChannelStats rtp_transport_channel_stats;
rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP;
rtp_transport_channel_stats.ice_transport_stats.connection_infos.push_back(
@@ -2336,7 +2349,9 @@
rtc::ToString(cricket::ICE_CANDIDATE_COMPONENT_RTP),
report->timestamp_us());
expected_rtp_transport.bytes_sent = 42;
+ expected_rtp_transport.packets_sent = 1;
expected_rtp_transport.bytes_received = 1337;
+ expected_rtp_transport.packets_received = 4;
expected_rtp_transport.dtls_state = RTCDtlsTransportState::kConnected;
expected_rtp_transport.selected_candidate_pair_changes = 1;
// Crypto parameters
diff --git a/pc/rtc_stats_integrationtest.cc b/pc/rtc_stats_integrationtest.cc
index 751195a..e627d45 100644
--- a/pc/rtc_stats_integrationtest.cc
+++ b/pc/rtc_stats_integrationtest.cc
@@ -1065,7 +1065,9 @@
bool VerifyRTCTransportStats(const RTCTransportStats& transport) {
RTCStatsVerifier verifier(report_, &transport);
verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_sent);
+ verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_sent);
verifier.TestMemberIsNonNegative<uint64_t>(transport.bytes_received);
+ verifier.TestMemberIsNonNegative<uint64_t>(transport.packets_received);
verifier.TestMemberIsOptionalIDReference(transport.rtcp_transport_stats_id,
RTCTransportStats::kType);
verifier.TestMemberIsDefined(transport.dtls_state);
diff --git a/stats/rtcstats_objects.cc b/stats/rtcstats_objects.cc
index ea2ba40..2fe8546 100644
--- a/stats/rtcstats_objects.cc
+++ b/stats/rtcstats_objects.cc
@@ -958,7 +958,9 @@
// clang-format off
WEBRTC_RTCSTATS_IMPL(RTCTransportStats, RTCStats, "transport",
&bytes_sent,
+ &packets_sent,
&bytes_received,
+ &packets_received,
&rtcp_transport_stats_id,
&dtls_state,
&selected_candidate_pair_id,
@@ -977,7 +979,9 @@
RTCTransportStats::RTCTransportStats(std::string&& id, int64_t timestamp_us)
: RTCStats(std::move(id), timestamp_us),
bytes_sent("bytesSent"),
+ packets_sent("packetsSent"),
bytes_received("bytesReceived"),
+ packets_received("packetsReceived"),
rtcp_transport_stats_id("rtcpTransportStatsId"),
dtls_state("dtlsState"),
selected_candidate_pair_id("selectedCandidatePairId"),
@@ -991,7 +995,9 @@
RTCTransportStats::RTCTransportStats(const RTCTransportStats& other)
: RTCStats(other.id(), other.timestamp_us()),
bytes_sent(other.bytes_sent),
+ packets_sent(other.packets_sent),
bytes_received(other.bytes_received),
+ packets_received(other.packets_received),
rtcp_transport_stats_id(other.rtcp_transport_stats_id),
dtls_state(other.dtls_state),
selected_candidate_pair_id(other.selected_candidate_pair_id),