Add an environment clock timestamp to SenderReportStats.

Add an environment clock timestamp to SenderReportStats and make it visible in rtc_stats_collector.cc. This make it possible to use the pc->GetConfiguration().stats_timestamp_with_environment_clock() flag to decide which timestamp to use when creating a RTCRemoteOutboundRtpStreamStats object.

This CL is the third (and possible the last) of a series of CLs that aim to replace the UTC timestamps in RTCStats objects to Environment clock timestamps. The other CLs where https://webrtc-review.googlesource.com/c/src/+/363946 and https://webrtc-review.googlesource.com/c/src/+/364782.

When Chromium and Google internal uses of RTCStats are updated to set the stats_timestamp_with_environment_clock configuration, the flag can be deleted.

Bug: chromium:369369568
Change-Id: Ic0b07d7b012505267bd6516f19a9ba90df4cafab
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365001
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Olov Brändström <brandstrom@google.com>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43206}
This commit is contained in:
Olov Brändström 2024-10-09 11:48:07 +02:00 committed by WebRTC LUCI CQ
parent eb0ba6b1ee
commit 51b682648e
11 changed files with 38 additions and 6 deletions

View File

@ -332,6 +332,8 @@ webrtc::AudioReceiveStreamInterface::Stats AudioReceiveStreamImpl::GetStats(
stats.decoding_plc_cng = ds.decoded_plc_cng;
stats.decoding_muted_output = ds.decoded_muted_output;
stats.last_sender_report_timestamp_ms =
call_stats.last_sender_report_timestamp_ms;
stats.last_sender_report_utc_timestamp_ms =
call_stats.last_sender_report_utc_timestamp_ms;
stats.last_sender_report_remote_utc_timestamp_ms =

View File

@ -872,6 +872,8 @@ CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const {
std::optional<RtpRtcpInterface::SenderReportStats> rtcp_sr_stats =
rtp_rtcp_->GetSenderReportStats();
if (rtcp_sr_stats.has_value()) {
stats.last_sender_report_timestamp_ms =
rtcp_sr_stats->last_arrival_timestamp.ms<int64_t>();
stats.last_sender_report_utc_timestamp_ms =
rtcp_sr_stats->last_arrival_ntp_timestamp.ToMs() -
rtc::kNtpJan1970Millisecs;

View File

@ -67,6 +67,11 @@ struct CallReceiveStatistics {
// Note that the timestamps below correspond to the time elapsed since the
// Unix epoch.
// https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
// TODO: bugs.webrtc.org/372393493: timestamps should use the type Timestamp,
// not int64_t.
std::optional<int64_t> last_sender_report_timestamp_ms;
// TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when
// linked issue is fixed.
std::optional<int64_t> last_sender_report_utc_timestamp_ms;
std::optional<int64_t> last_sender_report_remote_utc_timestamp_ms;
uint64_t sender_reports_packets_sent = 0;

View File

@ -100,6 +100,9 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
std::optional<int64_t> estimated_playout_ntp_timestamp_ms;
// Remote outbound stats derived by the received RTCP sender reports.
// https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
std::optional<int64_t> last_sender_report_timestamp_ms;
// TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when
// linked issue is fixed.
std::optional<int64_t> last_sender_report_utc_timestamp_ms;
std::optional<int64_t> last_sender_report_remote_utc_timestamp_ms;
uint64_t sender_reports_packets_sent = 0;

View File

@ -175,6 +175,9 @@ class VideoReceiveStreamInterface : public MediaReceiveStreamInterface {
// Remote outbound stats derived by the received RTCP sender reports.
// https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
std::optional<int64_t> last_sender_report_timestamp_ms;
// TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when
// linked issue is fixed.
std::optional<int64_t> last_sender_report_utc_timestamp_ms;
std::optional<int64_t> last_sender_report_remote_utc_timestamp_ms;
uint32_t sender_reports_packets_sent = 0;

View File

@ -482,6 +482,11 @@ struct MediaReceiverInfo {
// Remote outbound stats derived by the received RTCP sender reports.
// https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
// TODO: bugs.webrtc.org/372393493: timestamps should use the type Timestamp,
// not int64_t.
std::optional<int64_t> last_sender_report_timestamp_ms;
// TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when
// linked issue is fixed.
std::optional<int64_t> last_sender_report_utc_timestamp_ms;
std::optional<int64_t> last_sender_report_remote_utc_timestamp_ms;
uint64_t sender_reports_packets_sent = 0;

View File

@ -3844,6 +3844,7 @@ WebRtcVideoReceiveChannel::WebRtcVideoReceiveStream::GetVideoReceiverInfo(
}
// remote-outbound-rtp stats.
info.last_sender_report_timestamp_ms = stats.last_sender_report_timestamp_ms;
info.last_sender_report_utc_timestamp_ms =
stats.last_sender_report_utc_timestamp_ms;
info.last_sender_report_remote_utc_timestamp_ms =

View File

@ -2697,6 +2697,8 @@ bool WebRtcVoiceReceiveChannel::GetStats(VoiceMediaReceiveInfo* info,
stats.relative_packet_arrival_delay_seconds;
rinfo.interruption_count = stats.interruption_count;
rinfo.total_interruption_duration_ms = stats.total_interruption_duration_ms;
rinfo.last_sender_report_timestamp_ms =
stats.last_sender_report_timestamp_ms;
rinfo.last_sender_report_utc_timestamp_ms =
stats.last_sender_report_utc_timestamp_ms;
rinfo.last_sender_report_remote_utc_timestamp_ms =

View File

@ -551,6 +551,7 @@ bool RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
remote_sender_.last_remote_ntp_timestamp = sender_report.ntp();
remote_sender_.last_remote_rtp_timestamp = sender_report.rtp_timestamp();
remote_sender_.last_arrival_timestamp = env_.clock().CurrentTime();
remote_sender_.last_arrival_ntp_timestamp = env_.clock().CurrentNtpTime();
remote_sender_.packets_sent = sender_report.sender_packet_count();
remote_sender_.bytes_sent = sender_report.sender_octet_count();

View File

@ -146,7 +146,11 @@ class RtpRtcpInterface : public RtcpFeedbackSenderInterface {
// Stats for RTCP sender reports (SR) for a specific SSRC.
// Refer to https://tools.ietf.org/html/rfc3550#section-6.4.1.
struct SenderReportStats {
// Arrival timestamp (enviroment clock) for the last received RTCP SR.
Timestamp last_arrival_timestamp = Timestamp::Zero();
// Arrival NTP timestamp for the last received RTCP SR.
// TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when
// linked issue is fixed.
NtpTime last_arrival_ntp_timestamp;
// Received (a.k.a., remote) NTP timestamp for the last received RTCP SR.
NtpTime last_remote_ntp_timestamp;

View File

@ -521,8 +521,13 @@ CreateRemoteOutboundMediaStreamStats(
const std::string& mid,
cricket::MediaType media_type,
const RTCInboundRtpStreamStats& inbound_audio_stats,
const std::string& transport_id) {
if (!media_receiver_info.last_sender_report_utc_timestamp_ms.has_value()) {
const std::string& transport_id,
const bool stats_timestamp_with_environment_clock) {
std::optional<int64_t> last_sender_report_timestamp_ms =
stats_timestamp_with_environment_clock
? media_receiver_info.last_sender_report_timestamp_ms
: media_receiver_info.last_sender_report_utc_timestamp_ms;
if (!last_sender_report_timestamp_ms.has_value()) {
// Cannot create `RTCRemoteOutboundRtpStreamStats` when the RTCP SR arrival
// timestamp is not available - i.e., until the first sender report is
// received.
@ -534,8 +539,7 @@ CreateRemoteOutboundMediaStreamStats(
auto stats = std::make_unique<RTCRemoteOutboundRtpStreamStats>(
/*id=*/RTCRemoteOutboundRTPStreamStatsIDFromSSRC(
media_type, media_receiver_info.ssrc()),
Timestamp::Millis(
*media_receiver_info.last_sender_report_utc_timestamp_ms));
Timestamp::Millis(*last_sender_report_timestamp_ms));
// Populate.
// - RTCRtpStreamStats.
@ -1730,7 +1734,7 @@ void RTCStatsCollector::ProduceAudioRTPStreamStats_n(
// Remote-outbound.
auto remote_outbound_audio = CreateRemoteOutboundMediaStreamStats(
voice_receiver_info, mid, cricket::MEDIA_TYPE_AUDIO, *inbound_audio_ptr,
transport_id);
transport_id, stats_timestamp_with_environment_clock_);
// Add stats.
if (remote_outbound_audio) {
// When the remote outbound stats are available, the remote ID for the
@ -1825,7 +1829,7 @@ void RTCStatsCollector::ProduceVideoRTPStreamStats_n(
// Remote-outbound.
auto remote_outbound_video = CreateRemoteOutboundMediaStreamStats(
video_receiver_info, mid, cricket::MEDIA_TYPE_VIDEO, *inbound_video_ptr,
transport_id);
transport_id, stats_timestamp_with_environment_clock_);
// Add stats.
if (remote_outbound_video) {
// When the remote outbound stats are available, the remote ID for the