From 86f04ad135b6b0b3b05c3b79fa7c53b65a03c013 Mon Sep 17 00:00:00 2001 From: Di Wu Date: Sun, 28 Feb 2021 23:36:03 -0800 Subject: [PATCH] =?UTF-8?q?Populate=20=E2=80=9CfractionLost=E2=80=9D=20sta?= =?UTF-8?q?ts=20for=20remote=20inbound=20rtp=20streams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests: ./out/Default/peerconnection_unittests Manually tested with Chromium to see the data populated Spec: https://w3c.github.io/webrtc-stats/#remoteinboundrtpstats-dict* Bug: webrtc:12506 Change-Id: I60ef8061fb31deab06ca5f115246ceb5a8cdc5ec Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208960 Reviewed-by: Harald Alvestrand Reviewed-by: Henrik Boström Commit-Queue: Henrik Boström Cr-Commit-Position: refs/heads/master@{#33361} --- api/stats/rtcstats_objects.h | 3 +-- pc/rtc_stats_collector.cc | 2 ++ pc/rtc_stats_collector_unittest.cc | 4 ++++ pc/rtc_stats_integrationtest.cc | 1 + stats/rtcstats_objects.cc | 9 ++++++--- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h index 7e0970d889..f328326745 100644 --- a/api/stats/rtcstats_objects.h +++ b/api/stats/rtcstats_objects.h @@ -555,8 +555,7 @@ class RTC_EXPORT RTCRemoteInboundRtpStreamStats final : public RTCStats { // RTCRemoteInboundRtpStreamStats RTCStatsMember local_id; RTCStatsMember round_trip_time; - // TODO(hbos): The following RTCRemoteInboundRtpStreamStats metric should also - // be implemented: fractionLost. + RTCStatsMember fraction_lost; }; // https://w3c.github.io/webrtc-stats/#dom-rtcmediasourcestats diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 5a741a16cd..aa3b17bb7f 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -541,6 +541,8 @@ ProduceRemoteInboundRtpStreamStatsFromReportBlockData( remote_inbound->kind = media_type == cricket::MEDIA_TYPE_AUDIO ? "audio" : "video"; remote_inbound->packets_lost = report_block.packets_lost; + remote_inbound->fraction_lost = + static_cast(report_block.fraction_lost) / (1 << 8); remote_inbound->round_trip_time = static_cast(report_block_data.last_rtt_ms()) / rtc::kNumMillisecsPerSec; diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index cb300e0b1a..13c8f980ee 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -2678,6 +2678,7 @@ TEST_P(RTCStatsCollectorTestWithParamKind, const int64_t kReportBlockTimestampUtcUs = 123456789; const int64_t kRoundTripTimeMs = 13000; const double kRoundTripTimeSeconds = 13.0; + const uint8_t kFractionLost = 12; // The report block's timestamp cannot be from the future, set the fake clock // to match. @@ -2690,6 +2691,7 @@ TEST_P(RTCStatsCollectorTestWithParamKind, // |source_ssrc|, "SSRC of the RTP packet sender". report_block.source_ssrc = ssrc; report_block.packets_lost = 7; + report_block.fraction_lost = kFractionLost; ReportBlockData report_block_data; report_block_data.SetReportBlock(report_block, kReportBlockTimestampUtcUs); report_block_data.AddRoundTripTimeSample(1234); @@ -2708,6 +2710,8 @@ TEST_P(RTCStatsCollectorTestWithParamKind, "RTCRemoteInboundRtp" + MediaTypeUpperCase() + stream_id, kReportBlockTimestampUtcUs); expected_remote_inbound_rtp.ssrc = ssrc; + expected_remote_inbound_rtp.fraction_lost = + static_cast(kFractionLost) / (1 << 8); expected_remote_inbound_rtp.kind = MediaTypeLowerCase(); expected_remote_inbound_rtp.transport_id = "RTCTransport_TransportName_1"; // 1 for RTP (we have no RTCP diff --git a/pc/rtc_stats_integrationtest.cc b/pc/rtc_stats_integrationtest.cc index 6288f60b87..82f07cf4c6 100644 --- a/pc/rtc_stats_integrationtest.cc +++ b/pc/rtc_stats_integrationtest.cc @@ -1014,6 +1014,7 @@ class RTCStatsReportVerifier { verifier.TestMemberIsIDReference(remote_inbound_stream.codec_id, RTCCodecStats::kType); verifier.TestMemberIsDefined(remote_inbound_stream.packets_lost); + verifier.TestMemberIsDefined(remote_inbound_stream.fraction_lost); // Note that the existance of RTCCodecStats is needed for |codec_id| and // |jitter| to be present. verifier.TestMemberIsNonNegative(remote_inbound_stream.jitter); diff --git a/stats/rtcstats_objects.cc b/stats/rtcstats_objects.cc index 5a803de071..4e743dae2c 100644 --- a/stats/rtcstats_objects.cc +++ b/stats/rtcstats_objects.cc @@ -848,7 +848,8 @@ WEBRTC_RTCSTATS_IMPL( &packets_lost, &jitter, &local_id, - &round_trip_time) + &round_trip_time, + &fraction_lost) // clang-format on RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( @@ -867,7 +868,8 @@ RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( packets_lost("packetsLost"), jitter("jitter"), local_id("localId"), - round_trip_time("roundTripTime") {} + round_trip_time("roundTripTime"), + fraction_lost("fractionLost") {} RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( const RTCRemoteInboundRtpStreamStats& other) @@ -879,7 +881,8 @@ RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( packets_lost(other.packets_lost), jitter(other.jitter), local_id(other.local_id), - round_trip_time(other.round_trip_time) {} + round_trip_time(other.round_trip_time), + fraction_lost(other.fraction_lost) {} RTCRemoteInboundRtpStreamStats::~RTCRemoteInboundRtpStreamStats() {}