diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h index 3458d6fef7..f3492ae555 100644 --- a/api/stats/rtcstats_objects.h +++ b/api/stats/rtcstats_objects.h @@ -602,7 +602,9 @@ class RTC_EXPORT RTCTransportStats final : public RTCStats { ~RTCTransportStats() override; RTCStatsMember bytes_sent; + RTCStatsMember packets_sent; RTCStatsMember bytes_received; + RTCStatsMember packets_received; RTCStatsMember rtcp_transport_stats_id; // TODO(hbos): Support enum types? "RTCStatsMember"? RTCStatsMember dtls_state; diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index afb1457567..0863865a04 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -461,6 +461,7 @@ void Connection::OnReadPacket(const char* data, 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 a4f8036769..ebea2ab5b0 100644 --- a/p2p/base/connection_info.cc +++ b/p2p/base/connection_info.cc @@ -28,6 +28,7 @@ ConnectionInfo::ConnectionInfo() 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 a62e8aec00..b5e1c14433 100644 --- a/p2p/base/connection_info.h +++ b/p2p/base/connection_info.h @@ -54,6 +54,7 @@ struct ConnectionInfo { 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 523e9e8bc6..cfdee81403 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -1284,6 +1284,7 @@ TEST_F(P2PTransportChannelTest, GetStats) { 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 @@ TEST_F(P2PTransportChannelTest, GetStats) { 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 07e40cba50..be0d90d533 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -1744,7 +1744,9 @@ void RTCStatsCollector::ProduceTransportStats_n( 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 = @@ -1752,7 +1754,10 @@ void RTCStatsCollector::ProduceTransportStats_n( 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 a034c3e433..60259db9ca 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -2139,6 +2139,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { 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( @@ -2156,7 +2159,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { 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; @@ -2171,6 +2176,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { 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; @@ -2188,7 +2196,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { 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; @@ -2282,6 +2292,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) { 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( @@ -2304,7 +2317,9 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) { 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 a0fd2d0253..9e8656305d 100644 --- a/pc/rtc_stats_integrationtest.cc +++ b/pc/rtc_stats_integrationtest.cc @@ -1014,7 +1014,9 @@ class RTCStatsReportVerifier { bool VerifyRTCTransportStats(const RTCTransportStats& transport) { RTCStatsVerifier verifier(report_, &transport); verifier.TestMemberIsNonNegative(transport.bytes_sent); + verifier.TestMemberIsNonNegative(transport.packets_sent); verifier.TestMemberIsNonNegative(transport.bytes_received); + verifier.TestMemberIsNonNegative(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 6c7b8d2123..ea16444554 100644 --- a/stats/rtcstats_objects.cc +++ b/stats/rtcstats_objects.cc @@ -906,7 +906,9 @@ RTCVideoSourceStats::~RTCVideoSourceStats() {} // 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, @@ -925,7 +927,9 @@ RTCTransportStats::RTCTransportStats(const std::string& id, 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"), @@ -939,7 +943,9 @@ RTCTransportStats::RTCTransportStats(std::string&& id, int64_t timestamp_us) 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),