diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc index 948f19804a..6edc7d03f1 100644 --- a/audio/audio_receive_stream.cc +++ b/audio/audio_receive_stream.cc @@ -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 = diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index da58924baf..865fe00442 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -872,6 +872,8 @@ CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const { std::optional 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(); stats.last_sender_report_utc_timestamp_ms = rtcp_sr_stats->last_arrival_ntp_timestamp.ToMs() - rtc::kNtpJan1970Millisecs; diff --git a/audio/channel_receive.h b/audio/channel_receive.h index 98da20c479..afac2944ca 100644 --- a/audio/channel_receive.h +++ b/audio/channel_receive.h @@ -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 last_sender_report_timestamp_ms; + // TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when + // linked issue is fixed. std::optional last_sender_report_utc_timestamp_ms; std::optional last_sender_report_remote_utc_timestamp_ms; uint64_t sender_reports_packets_sent = 0; diff --git a/call/audio_receive_stream.h b/call/audio_receive_stream.h index 655f0282af..f66abdff3c 100644 --- a/call/audio_receive_stream.h +++ b/call/audio_receive_stream.h @@ -100,6 +100,9 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface { std::optional 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 last_sender_report_timestamp_ms; + // TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when + // linked issue is fixed. std::optional last_sender_report_utc_timestamp_ms; std::optional last_sender_report_remote_utc_timestamp_ms; uint64_t sender_reports_packets_sent = 0; diff --git a/call/video_receive_stream.h b/call/video_receive_stream.h index 2e9755452d..fe27ec1fba 100644 --- a/call/video_receive_stream.h +++ b/call/video_receive_stream.h @@ -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 last_sender_report_timestamp_ms; + // TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when + // linked issue is fixed. std::optional last_sender_report_utc_timestamp_ms; std::optional last_sender_report_remote_utc_timestamp_ms; uint32_t sender_reports_packets_sent = 0; diff --git a/media/base/media_channel.h b/media/base/media_channel.h index f8c1fede5b..a6d90f3b1c 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -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 last_sender_report_timestamp_ms; + // TODO: bugs.webrtc.org/370535296: Remove the ntp arrival timestamp when + // linked issue is fixed. std::optional last_sender_report_utc_timestamp_ms; std::optional last_sender_report_remote_utc_timestamp_ms; uint64_t sender_reports_packets_sent = 0; diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 12ee581378..dc978a7830 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -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 = diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index f78d1eb03e..3dda76a873 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -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 = diff --git a/modules/rtp_rtcp/source/rtcp_receiver.cc b/modules/rtp_rtcp/source/rtcp_receiver.cc index 4014990ecb..8732b3772c 100644 --- a/modules/rtp_rtcp/source/rtcp_receiver.cc +++ b/modules/rtp_rtcp/source/rtcp_receiver.cc @@ -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(); diff --git a/modules/rtp_rtcp/source/rtp_rtcp_interface.h b/modules/rtp_rtcp/source/rtp_rtcp_interface.h index a6bf2df51b..85152357e1 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_interface.h +++ b/modules/rtp_rtcp/source/rtp_rtcp_interface.h @@ -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; diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 08f39618c0..60265f4093 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -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 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( /*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