Avoid depending on codec info for audio jitter stat.

The clock rate is already known by the RTP statistician.

Also included some minor code cleanup.

Bug: b/331602608
Change-Id: I335fa2a1cfd7dcceb286706d295a175a92f6797c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/368920
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43436}
This commit is contained in:
Jakob Ivarsson 2024-11-21 15:35:46 +00:00 committed by WebRTC LUCI CQ
parent 2e7e049bb4
commit 8da15c43dd
5 changed files with 33 additions and 43 deletions

View File

@ -255,25 +255,35 @@ webrtc::AudioReceiveStreamInterface::Stats AudioReceiveStreamImpl::GetStats(
webrtc::AudioReceiveStreamInterface::Stats stats;
stats.remote_ssrc = remote_ssrc();
webrtc::CallReceiveStatistics call_stats =
channel_receive_->GetRTCPStatistics();
auto receive_codec = channel_receive_->GetReceiveCodec();
if (receive_codec) {
stats.codec_name = receive_codec->second.name;
stats.codec_payload_type = receive_codec->first;
int clockrate_khz = receive_codec->second.clockrate_hz / 1000;
if (clockrate_khz > 0) {
stats.jitter_ms = call_stats.jitterSamples / clockrate_khz;
}
}
webrtc::CallReceiveStatistics call_stats =
channel_receive_->GetRTCPStatistics();
stats.payload_bytes_received = call_stats.payload_bytes_received;
stats.header_and_padding_bytes_received =
call_stats.header_and_padding_bytes_received;
stats.packets_received = call_stats.packetsReceived;
stats.packets_lost = call_stats.cumulativeLost;
stats.packets_received = call_stats.packets_received;
stats.packets_lost = call_stats.packets_lost;
stats.jitter_ms = call_stats.jitter_ms;
stats.nacks_sent = call_stats.nacks_sent;
stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms;
stats.last_packet_received = call_stats.last_packet_received;
stats.last_sender_report_timestamp = call_stats.last_sender_report_timestamp;
stats.last_sender_report_utc_timestamp =
call_stats.last_sender_report_utc_timestamp;
stats.last_sender_report_remote_utc_timestamp =
call_stats.last_sender_report_remote_utc_timestamp;
stats.sender_reports_packets_sent = call_stats.sender_reports_packets_sent;
stats.sender_reports_bytes_sent = call_stats.sender_reports_bytes_sent;
stats.sender_reports_reports_count = call_stats.sender_reports_reports_count;
stats.round_trip_time = call_stats.round_trip_time;
stats.round_trip_time_measurements = call_stats.round_trip_time_measurements;
stats.total_round_trip_time = call_stats.total_round_trip_time;
stats.delay_estimate_ms = channel_receive_->GetDelayEstimate();
stats.audio_level = channel_receive_->GetSpeechOutputLevelFullRange();
stats.total_output_energy = channel_receive_->GetTotalOutputEnergy();
@ -332,18 +342,6 @@ 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 = call_stats.last_sender_report_timestamp;
stats.last_sender_report_utc_timestamp =
call_stats.last_sender_report_utc_timestamp;
stats.last_sender_report_remote_utc_timestamp =
call_stats.last_sender_report_remote_utc_timestamp;
stats.sender_reports_packets_sent = call_stats.sender_reports_packets_sent;
stats.sender_reports_bytes_sent = call_stats.sender_reports_bytes_sent;
stats.sender_reports_reports_count = call_stats.sender_reports_reports_count;
stats.round_trip_time = call_stats.round_trip_time;
stats.round_trip_time_measurements = call_stats.round_trip_time_measurements;
stats.total_round_trip_time = call_stats.total_round_trip_time;
return stats;
}

View File

@ -250,13 +250,11 @@ TEST(AudioReceiveStreamTest, GetStats) {
EXPECT_EQ(kCallStats.payload_bytes_received, stats.payload_bytes_received);
EXPECT_EQ(kCallStats.header_and_padding_bytes_received,
stats.header_and_padding_bytes_received);
EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived),
EXPECT_EQ(static_cast<uint32_t>(kCallStats.packets_received),
stats.packets_received);
EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost);
EXPECT_EQ(kCallStats.packets_lost, stats.packets_lost);
EXPECT_EQ(kReceiveCodec.second.name, stats.codec_name);
EXPECT_EQ(
kCallStats.jitterSamples / (kReceiveCodec.second.clockrate_hz / 1000),
stats.jitter_ms);
EXPECT_EQ(kCallStats.jitter_ms, stats.jitter_ms);
EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms);
EXPECT_EQ(kNetworkStats.preferredBufferSize,
stats.jitter_buffer_preferred_ms);
@ -320,7 +318,7 @@ TEST(AudioReceiveStreamTest, GetStats) {
EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng);
EXPECT_EQ(kAudioDecodeStats.decoded_muted_output,
stats.decoding_muted_output);
EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_,
EXPECT_EQ(kCallStats.capture_start_ntp_time_ms,
stats.capture_start_ntp_time_ms);
EXPECT_EQ(kPlayoutNtpTimestampMs, stats.estimated_playout_ntp_timestamp_ms);
recv_stream->UnregisterFromTransport();

View File

@ -839,23 +839,17 @@ CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const {
rtp_stats = statistician->GetStats();
}
stats.cumulativeLost = rtp_stats.packets_lost;
stats.jitterSamples = rtp_stats.jitter;
stats.packets_lost = rtp_stats.packets_lost;
stats.jitter_ms = rtp_stats.interarrival_jitter.ms();
// Data counters.
if (statistician) {
stats.payload_bytes_received = rtp_stats.packet_counter.payload_bytes;
stats.header_and_padding_bytes_received =
rtp_stats.packet_counter.header_bytes +
rtp_stats.packet_counter.padding_bytes;
stats.packetsReceived = rtp_stats.packet_counter.packets;
stats.packets_received = rtp_stats.packet_counter.packets;
stats.last_packet_received = rtp_stats.last_packet_received;
} else {
stats.payload_bytes_received = 0;
stats.header_and_padding_bytes_received = 0;
stats.packetsReceived = 0;
stats.last_packet_received = std::nullopt;
}
{
@ -866,7 +860,7 @@ CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const {
// Timestamps.
{
MutexLock lock(&ts_stats_lock_);
stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
stats.capture_start_ntp_time_ms = capture_start_ntp_time_ms_;
}
std::optional<RtpRtcpInterface::SenderReportStats> rtcp_sr_stats =

View File

@ -50,15 +50,15 @@ class RtpPacketReceived;
class RtpRtcp;
struct CallReceiveStatistics {
int cumulativeLost;
unsigned int jitterSamples;
int packets_lost = 0;
uint32_t jitter_ms = 0;
int64_t payload_bytes_received = 0;
int64_t header_and_padding_bytes_received = 0;
int packetsReceived;
int packets_received = 0;
uint32_t nacks_sent = 0;
// The capture NTP time (in local timebase) of the first played out audio
// frame.
int64_t capture_start_ntp_time_ms_;
int64_t capture_start_ntp_time_ms = 0;
// The timestamp at which the last packet was received, i.e. the time of the
// local clock when it was received - not the RTP timestamp of that packet.
// https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
@ -77,7 +77,7 @@ struct CallReceiveStatistics {
uint64_t sender_reports_reports_count = 0;
std::optional<TimeDelta> round_trip_time;
TimeDelta total_round_trip_time = TimeDelta::Zero();
int round_trip_time_measurements;
int round_trip_time_measurements = 0;
};
namespace voe {

View File

@ -151,7 +151,7 @@ class ChannelReceiveTest : public Test {
channel.OnRtpPacket(CreateRtpPacket());
channel.GetAudioFrameWithInfo(kSampleRateHz, &audio_frame);
CallReceiveStatistics stats = channel.GetRTCPStatistics();
return stats.capture_start_ntp_time_ms_;
return stats.capture_start_ntp_time_ms;
}
protected: