Fix standard GetStats to not modify NetEq state.

Add a get_and_clear_legacy_stats flag to AudioReceiveStream::GetStats,
to distinguish calls from standard GetStats and legacy GetStats.

Add const method NetEq::CurrentNetworkStatistics to get current
values of stateless NetEq stats. Standard GetStats will then call this
method instead of NetEq::NetworkStatistics.

Bug: webrtc:11622
Change-Id: I3833a246a9e39b18c99657a738da22c6e2bd5f5e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/183600
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32092}
This commit is contained in:
Niels Möller 2020-09-14 10:47:50 +02:00 committed by Commit Bot
parent 71d7c8e3cd
commit 6b4d962947
29 changed files with 143 additions and 81 deletions

View File

@ -274,6 +274,9 @@ class NetEq {
// after the call. // after the call.
virtual int NetworkStatistics(NetEqNetworkStatistics* stats) = 0; virtual int NetworkStatistics(NetEqNetworkStatistics* stats) = 0;
// Current values only, not resetting any state.
virtual NetEqNetworkStatistics CurrentNetworkStatistics() const = 0;
// Returns a copy of this class's lifetime statistics. These statistics are // Returns a copy of this class's lifetime statistics. These statistics are
// never reset. // never reset.
virtual NetEqLifetimeStatistics GetLifetimeStatistics() const = 0; virtual NetEqLifetimeStatistics GetLifetimeStatistics() const = 0;

View File

@ -173,7 +173,8 @@ void AudioReceiveStream::Stop() {
audio_state()->RemoveReceivingStream(this); audio_state()->RemoveReceivingStream(this);
} }
webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats(
bool get_and_clear_legacy_stats) const {
RTC_DCHECK_RUN_ON(&worker_thread_checker_); RTC_DCHECK_RUN_ON(&worker_thread_checker_);
webrtc::AudioReceiveStream::Stats stats; webrtc::AudioReceiveStream::Stats stats;
stats.remote_ssrc = config_.rtp.remote_ssrc; stats.remote_ssrc = config_.rtp.remote_ssrc;
@ -210,7 +211,7 @@ webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
rtc::TimeMillis()); rtc::TimeMillis());
// Get jitter buffer and total delay (alg + jitter + playout) stats. // Get jitter buffer and total delay (alg + jitter + playout) stats.
auto ns = channel_receive_->GetNetworkStatistics(); auto ns = channel_receive_->GetNetworkStatistics(get_and_clear_legacy_stats);
stats.fec_packets_received = ns.fecPacketsReceived; stats.fec_packets_received = ns.fecPacketsReceived;
stats.fec_packets_discarded = ns.fecPacketsDiscarded; stats.fec_packets_discarded = ns.fecPacketsDiscarded;
stats.jitter_buffer_ms = ns.currentBufferSize; stats.jitter_buffer_ms = ns.currentBufferSize;

View File

@ -67,7 +67,8 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream,
void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override; void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override;
void Start() override; void Start() override;
void Stop() override; void Stop() override;
webrtc::AudioReceiveStream::Stats GetStats() const override; webrtc::AudioReceiveStream::Stats GetStats(
bool get_and_clear_legacy_stats) const override;
void SetSink(AudioSinkInterface* sink) override; void SetSink(AudioSinkInterface* sink) override;
void SetGain(float gain) override; void SetGain(float gain) override;
bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override; bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override;

View File

@ -146,7 +146,7 @@ struct ConfigHelper {
.WillOnce(Return(kTotalOutputEnergy)); .WillOnce(Return(kTotalOutputEnergy));
EXPECT_CALL(*channel_receive_, GetTotalOutputDuration()) EXPECT_CALL(*channel_receive_, GetTotalOutputDuration())
.WillOnce(Return(kTotalOutputDuration)); .WillOnce(Return(kTotalOutputDuration));
EXPECT_CALL(*channel_receive_, GetNetworkStatistics()) EXPECT_CALL(*channel_receive_, GetNetworkStatistics(_))
.WillOnce(Return(kNetworkStats)); .WillOnce(Return(kNetworkStats));
EXPECT_CALL(*channel_receive_, GetDecodingCallStatistics()) EXPECT_CALL(*channel_receive_, GetDecodingCallStatistics())
.WillOnce(Return(kAudioDecodeStats)); .WillOnce(Return(kAudioDecodeStats));
@ -219,7 +219,8 @@ TEST(AudioReceiveStreamTest, GetStats) {
ConfigHelper helper(use_null_audio_processing); ConfigHelper helper(use_null_audio_processing);
auto recv_stream = helper.CreateAudioReceiveStream(); auto recv_stream = helper.CreateAudioReceiveStream();
helper.SetupMockForGetStats(); helper.SetupMockForGetStats();
AudioReceiveStream::Stats stats = recv_stream->GetStats(); AudioReceiveStream::Stats stats =
recv_stream->GetStats(/*get_and_clear_legacy_stats=*/true);
EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc);
EXPECT_EQ(kCallStats.payload_bytes_rcvd, stats.payload_bytes_rcvd); EXPECT_EQ(kCallStats.payload_bytes_rcvd, stats.payload_bytes_rcvd);
EXPECT_EQ(kCallStats.header_and_padding_bytes_rcvd, EXPECT_EQ(kCallStats.header_and_padding_bytes_rcvd,

View File

@ -128,7 +128,8 @@ class ChannelReceive : public ChannelReceiveInterface {
double GetTotalOutputDuration() const override; double GetTotalOutputDuration() const override;
// Stats. // Stats.
NetworkStatistics GetNetworkStatistics() const override; NetworkStatistics GetNetworkStatistics(
bool get_and_clear_legacy_stats) const override;
AudioDecodingCallStats GetDecodingCallStatistics() const override; AudioDecodingCallStats GetDecodingCallStatistics() const override;
// Audio+Video Sync. // Audio+Video Sync.
@ -801,10 +802,11 @@ void ChannelReceive::SetDepacketizerToDecoderFrameTransformer(
InitFrameTransformerDelegate(std::move(frame_transformer)); InitFrameTransformerDelegate(std::move(frame_transformer));
} }
NetworkStatistics ChannelReceive::GetNetworkStatistics() const { NetworkStatistics ChannelReceive::GetNetworkStatistics(
bool get_and_clear_legacy_stats) const {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
NetworkStatistics stats; NetworkStatistics stats;
acm_receiver_.GetNetworkStatistics(&stats); acm_receiver_.GetNetworkStatistics(&stats, get_and_clear_legacy_stats);
return stats; return stats;
} }

View File

@ -99,7 +99,8 @@ class ChannelReceiveInterface : public RtpPacketSinkInterface {
virtual double GetTotalOutputDuration() const = 0; virtual double GetTotalOutputDuration() const = 0;
// Stats. // Stats.
virtual NetworkStatistics GetNetworkStatistics() const = 0; virtual NetworkStatistics GetNetworkStatistics(
bool get_and_clear_legacy_stats) const = 0;
virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0; virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
// Audio+Video Sync. // Audio+Video Sync.

View File

@ -35,7 +35,10 @@ class MockChannelReceive : public voe::ChannelReceiveInterface {
(override)); (override));
MOCK_METHOD(void, ResetReceiverCongestionControlObjects, (), (override)); MOCK_METHOD(void, ResetReceiverCongestionControlObjects, (), (override));
MOCK_METHOD(CallReceiveStatistics, GetRTCPStatistics, (), (const, override)); MOCK_METHOD(CallReceiveStatistics, GetRTCPStatistics, (), (const, override));
MOCK_METHOD(NetworkStatistics, GetNetworkStatistics, (), (const, override)); MOCK_METHOD(NetworkStatistics,
GetNetworkStatistics,
(bool),
(const, override));
MOCK_METHOD(AudioDecodingCallStats, MOCK_METHOD(AudioDecodingCallStats,
GetDecodingCallStatistics, GetDecodingCallStatistics,
(), (),

View File

@ -65,7 +65,8 @@ class NoLossTest : public AudioEndToEndTest {
EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood_recent_max); EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood_recent_max);
EXPECT_EQ(false, send_stats.typing_noise_detected); EXPECT_EQ(false, send_stats.typing_noise_detected);
AudioReceiveStream::Stats recv_stats = receive_stream()->GetStats(); AudioReceiveStream::Stats recv_stats =
receive_stream()->GetStats(/*get_and_clear_legacy_stats=*/true);
EXPECT_PRED2(IsNear, kBytesSent, recv_stats.payload_bytes_rcvd); EXPECT_PRED2(IsNear, kBytesSent, recv_stats.payload_bytes_rcvd);
EXPECT_PRED2(IsNear, kPacketsSent, recv_stats.packets_rcvd); EXPECT_PRED2(IsNear, kPacketsSent, recv_stats.packets_rcvd);
EXPECT_EQ(0u, recv_stats.packets_lost); EXPECT_EQ(0u, recv_stats.packets_lost);

View File

@ -167,7 +167,8 @@ class AudioReceiveStream {
// When a stream is stopped, it can't receive, process or deliver packets. // When a stream is stopped, it can't receive, process or deliver packets.
virtual void Stop() = 0; virtual void Stop() = 0;
virtual Stats GetStats() const = 0; virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0;
Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); }
// Sets an audio sink that receives unmixed audio from the receive stream. // Sets an audio sink that receives unmixed audio from the receive stream.
// Ownership of the sink is managed by the caller. // Ownership of the sink is managed by the caller.

View File

@ -183,7 +183,8 @@ absl::optional<int> FakeVoiceMediaChannel::GetBaseMinimumPlayoutDelayMs(
} }
return absl::nullopt; return absl::nullopt;
} }
bool FakeVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { bool FakeVoiceMediaChannel::GetStats(VoiceMediaInfo* info,
bool get_and_clear_legacy_stats) {
return false; return false;
} }
void FakeVoiceMediaChannel::SetRawAudioSink( void FakeVoiceMediaChannel::SetRawAudioSink(

View File

@ -349,7 +349,7 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
absl::optional<int> GetBaseMinimumPlayoutDelayMs( absl::optional<int> GetBaseMinimumPlayoutDelayMs(
uint32_t ssrc) const override; uint32_t ssrc) const override;
bool GetStats(VoiceMediaInfo* info) override; bool GetStats(VoiceMediaInfo* info, bool get_and_clear_legacy_stats) override;
void SetRawAudioSink( void SetRawAudioSink(
uint32_t ssrc, uint32_t ssrc,

View File

@ -834,7 +834,8 @@ class VoiceMediaChannel : public MediaChannel, public Delayable {
// DTMF event 0-9, *, #, A-D. // DTMF event 0-9, *, #, A-D.
virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0; virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0;
// Gets quality stats for the channel. // Gets quality stats for the channel.
virtual bool GetStats(VoiceMediaInfo* info) = 0; virtual bool GetStats(VoiceMediaInfo* info,
bool get_and_clear_legacy_stats) = 0;
virtual void SetRawAudioSink( virtual void SetRawAudioSink(
uint32_t ssrc, uint32_t ssrc,

View File

@ -100,7 +100,8 @@ void FakeAudioReceiveStream::Reconfigure(
config_ = config; config_ = config;
} }
webrtc::AudioReceiveStream::Stats FakeAudioReceiveStream::GetStats() const { webrtc::AudioReceiveStream::Stats FakeAudioReceiveStream::GetStats(
bool get_and_clear_legacy_stats) const {
return stats_; return stats_;
} }

View File

@ -104,7 +104,8 @@ class FakeAudioReceiveStream final : public webrtc::AudioReceiveStream {
void Start() override { started_ = true; } void Start() override { started_ = true; }
void Stop() override { started_ = false; } void Stop() override { started_ = false; }
webrtc::AudioReceiveStream::Stats GetStats() const override; webrtc::AudioReceiveStream::Stats GetStats(
bool get_and_clear_legacy_stats) const override;
void SetSink(webrtc::AudioSinkInterface* sink) override; void SetSink(webrtc::AudioSinkInterface* sink) override;
void SetGain(float gain) override; void SetGain(float gain) override;
bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override { bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override {

View File

@ -1249,10 +1249,11 @@ class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream {
} }
} }
webrtc::AudioReceiveStream::Stats GetStats() const { webrtc::AudioReceiveStream::Stats GetStats(
bool get_and_clear_legacy_stats) const {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
RTC_DCHECK(stream_); RTC_DCHECK(stream_);
return stream_->GetStats(); return stream_->GetStats(get_and_clear_legacy_stats);
} }
void SetRawAudioSink(std::unique_ptr<webrtc::AudioSinkInterface> sink) { void SetRawAudioSink(std::unique_ptr<webrtc::AudioSinkInterface> sink) {
@ -2300,7 +2301,8 @@ void WebRtcVoiceMediaChannel::OnReadyToSend(bool ready) {
ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); ready ? webrtc::kNetworkUp : webrtc::kNetworkDown);
} }
bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info,
bool get_and_clear_legacy_stats) {
TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::GetStats"); TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::GetStats");
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
RTC_DCHECK(info); RTC_DCHECK(info);
@ -2353,7 +2355,8 @@ bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) {
continue; continue;
} }
} }
webrtc::AudioReceiveStream::Stats stats = stream.second->GetStats(); webrtc::AudioReceiveStream::Stats stats =
stream.second->GetStats(get_and_clear_legacy_stats);
VoiceReceiverInfo rinfo; VoiceReceiverInfo rinfo;
rinfo.add_ssrc(stats.remote_ssrc); rinfo.add_ssrc(stats.remote_ssrc);
rinfo.payload_bytes_rcvd = stats.payload_bytes_rcvd; rinfo.payload_bytes_rcvd = stats.payload_bytes_rcvd;

View File

@ -195,7 +195,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
void OnNetworkRouteChanged(const std::string& transport_name, void OnNetworkRouteChanged(const std::string& transport_name,
const rtc::NetworkRoute& network_route) override; const rtc::NetworkRoute& network_route) override;
void OnReadyToSend(bool ready) override; void OnReadyToSend(bool ready) override;
bool GetStats(VoiceMediaInfo* info) override; bool GetStats(VoiceMediaInfo* info, bool get_and_clear_legacy_stats) override;
// Set the audio sink for an existing stream. // Set the audio sink for an existing stream.
void SetRawAudioSink( void SetRawAudioSink(

View File

@ -2346,7 +2346,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
{ {
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
cricket::VoiceMediaInfo info; cricket::VoiceMediaInfo info;
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
// We have added 4 send streams. We should see empty stats for all. // We have added 4 send streams. We should see empty stats for all.
EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size()); EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size());
@ -2365,7 +2366,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
cricket::VoiceMediaInfo info; cricket::VoiceMediaInfo info;
EXPECT_TRUE(channel_->RemoveRecvStream(kSsrcY)); EXPECT_TRUE(channel_->RemoveRecvStream(kSsrcY));
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size()); EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size());
EXPECT_EQ(0u, info.receivers.size()); EXPECT_EQ(0u, info.receivers.size());
} }
@ -2377,7 +2379,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) {
DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
SetAudioReceiveStreamStats(); SetAudioReceiveStreamStats();
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size()); EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size());
EXPECT_EQ(1u, info.receivers.size()); EXPECT_EQ(1u, info.receivers.size());
VerifyVoiceReceiverInfo(info.receivers[0]); VerifyVoiceReceiverInfo(info.receivers[0]);
@ -2550,7 +2553,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStats) {
{ {
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
cricket::VoiceMediaInfo info; cricket::VoiceMediaInfo info;
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
// We have added one send stream. We should see the stats we've set. // We have added one send stream. We should see the stats we've set.
EXPECT_EQ(1u, info.senders.size()); EXPECT_EQ(1u, info.senders.size());
@ -2565,7 +2569,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStats) {
cricket::VoiceMediaInfo info; cricket::VoiceMediaInfo info;
SetSend(true); SetSend(true);
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
VerifyVoiceSenderInfo(info.senders[0], true); VerifyVoiceSenderInfo(info.senders[0], true);
VerifyVoiceSendRecvCodecs(info); VerifyVoiceSendRecvCodecs(info);
} }
@ -2575,7 +2580,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStats) {
cricket::VoiceMediaInfo info; cricket::VoiceMediaInfo info;
EXPECT_TRUE(channel_->RemoveRecvStream(kSsrcY)); EXPECT_TRUE(channel_->RemoveRecvStream(kSsrcY));
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
EXPECT_EQ(1u, info.senders.size()); EXPECT_EQ(1u, info.senders.size());
EXPECT_EQ(0u, info.receivers.size()); EXPECT_EQ(0u, info.receivers.size());
} }
@ -2587,7 +2593,8 @@ TEST_P(WebRtcVoiceEngineTestFake, GetStats) {
DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
SetAudioReceiveStreamStats(); SetAudioReceiveStreamStats();
EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0)); EXPECT_CALL(*adm_, GetPlayoutUnderrunCount()).WillOnce(Return(0));
EXPECT_EQ(true, channel_->GetStats(&info)); EXPECT_EQ(true,
channel_->GetStats(&info, /*get_and_clear_legacy_stats=*/true));
EXPECT_EQ(1u, info.senders.size()); EXPECT_EQ(1u, info.senders.size());
EXPECT_EQ(1u, info.receivers.size()); EXPECT_EQ(1u, info.receivers.size());
VerifyVoiceReceiverInfo(info.receivers[0]); VerifyVoiceReceiverInfo(info.receivers[0]);

View File

@ -244,26 +244,45 @@ absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder()
return std::make_pair(last_decoder_->payload_type, last_decoder_->sdp_format); return std::make_pair(last_decoder_->payload_type, last_decoder_->sdp_format);
} }
void AcmReceiver::GetNetworkStatistics(NetworkStatistics* acm_stat) const { void AcmReceiver::GetNetworkStatistics(
NetworkStatistics* acm_stat,
bool get_and_clear_legacy_stats /* = true */) const {
NetEqNetworkStatistics neteq_stat; NetEqNetworkStatistics neteq_stat;
if (get_and_clear_legacy_stats) {
// NetEq function always returns zero, so we don't check the return value. // NetEq function always returns zero, so we don't check the return value.
neteq_->NetworkStatistics(&neteq_stat); neteq_->NetworkStatistics(&neteq_stat);
acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms;
acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms;
acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false;
acm_stat->currentPacketLossRate = neteq_stat.packet_loss_rate; acm_stat->currentPacketLossRate = neteq_stat.packet_loss_rate;
acm_stat->currentExpandRate = neteq_stat.expand_rate; acm_stat->currentExpandRate = neteq_stat.expand_rate;
acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate; acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate;
acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate; acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate;
acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate; acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate;
acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate; acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate;
acm_stat->currentSecondaryDiscardedRate = neteq_stat.secondary_discarded_rate; acm_stat->currentSecondaryDiscardedRate =
neteq_stat.secondary_discarded_rate;
acm_stat->addedSamples = neteq_stat.added_zero_samples; acm_stat->addedSamples = neteq_stat.added_zero_samples;
acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms; acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms;
acm_stat->medianWaitingTimeMs = neteq_stat.median_waiting_time_ms; acm_stat->medianWaitingTimeMs = neteq_stat.median_waiting_time_ms;
acm_stat->minWaitingTimeMs = neteq_stat.min_waiting_time_ms; acm_stat->minWaitingTimeMs = neteq_stat.min_waiting_time_ms;
acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms; acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms;
} else {
neteq_stat = neteq_->CurrentNetworkStatistics();
acm_stat->currentPacketLossRate = 0;
acm_stat->currentExpandRate = 0;
acm_stat->currentSpeechExpandRate = 0;
acm_stat->currentPreemptiveRate = 0;
acm_stat->currentAccelerateRate = 0;
acm_stat->currentSecondaryDecodedRate = 0;
acm_stat->currentSecondaryDiscardedRate = 0;
acm_stat->addedSamples = 0;
acm_stat->meanWaitingTimeMs = -1;
acm_stat->medianWaitingTimeMs = -1;
acm_stat->minWaitingTimeMs = -1;
acm_stat->maxWaitingTimeMs = 1;
}
acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms;
acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms;
acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false;
NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics(); NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics();
acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received; acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received;

View File

@ -138,7 +138,8 @@ class AcmReceiver {
// Output: // Output:
// - statistics : The current network statistics. // - statistics : The current network statistics.
// //
void GetNetworkStatistics(NetworkStatistics* statistics) const; void GetNetworkStatistics(NetworkStatistics* statistics,
bool get_and_clear_legacy_stats = true) const;
// //
// Flushes the NetEq packet and speech buffers. // Flushes the NetEq packet and speech buffers.

View File

@ -387,17 +387,9 @@ int NetEqImpl::FilteredCurrentDelayMs() const {
int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) { int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
assert(decoder_database_.get()); assert(decoder_database_.get());
const size_t total_samples_in_buffers = *stats = CurrentNetworkStatisticsInternal();
packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + stats_->GetNetworkStatistics(decoder_frame_length_, stats);
sync_buffer_->FutureLength();
assert(controller_.get());
stats->preferred_buffer_size_ms = controller_->TargetLevelMs();
stats->jitter_peaks_found = controller_->PeakFound();
stats_->GetNetworkStatistics(fs_hz_, total_samples_in_buffers,
decoder_frame_length_, stats);
// Compensate for output delay chain. // Compensate for output delay chain.
stats->current_buffer_size_ms += output_delay_chain_ms_;
stats->preferred_buffer_size_ms += output_delay_chain_ms_;
stats->mean_waiting_time_ms += output_delay_chain_ms_; stats->mean_waiting_time_ms += output_delay_chain_ms_;
stats->median_waiting_time_ms += output_delay_chain_ms_; stats->median_waiting_time_ms += output_delay_chain_ms_;
stats->min_waiting_time_ms += output_delay_chain_ms_; stats->min_waiting_time_ms += output_delay_chain_ms_;
@ -405,6 +397,31 @@ int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
return 0; return 0;
} }
NetEqNetworkStatistics NetEqImpl::CurrentNetworkStatistics() const {
MutexLock lock(&mutex_);
return CurrentNetworkStatisticsInternal();
}
NetEqNetworkStatistics NetEqImpl::CurrentNetworkStatisticsInternal() const {
assert(decoder_database_.get());
NetEqNetworkStatistics stats;
const size_t total_samples_in_buffers =
packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) +
sync_buffer_->FutureLength();
assert(controller_.get());
stats.preferred_buffer_size_ms = controller_->TargetLevelMs();
stats.jitter_peaks_found = controller_->PeakFound();
RTC_DCHECK_GT(fs_hz_, 0);
stats.current_buffer_size_ms =
static_cast<uint16_t>(total_samples_in_buffers * 1000 / fs_hz_);
// Compensate for output delay chain.
stats.current_buffer_size_ms += output_delay_chain_ms_;
stats.preferred_buffer_size_ms += output_delay_chain_ms_;
return stats;
}
NetEqLifetimeStatistics NetEqImpl::GetLifetimeStatistics() const { NetEqLifetimeStatistics NetEqImpl::GetLifetimeStatistics() const {
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
return stats_->GetLifetimeStatistics(); return stats_->GetLifetimeStatistics();

View File

@ -162,6 +162,8 @@ class NetEqImpl : public webrtc::NetEq {
// after the call. // after the call.
int NetworkStatistics(NetEqNetworkStatistics* stats) override; int NetworkStatistics(NetEqNetworkStatistics* stats) override;
NetEqNetworkStatistics CurrentNetworkStatistics() const override;
NetEqLifetimeStatistics GetLifetimeStatistics() const override; NetEqLifetimeStatistics GetLifetimeStatistics() const override;
NetEqOperationsAndState GetOperationsAndState() const override; NetEqOperationsAndState GetOperationsAndState() const override;
@ -330,6 +332,9 @@ class NetEqImpl : public webrtc::NetEq {
virtual void UpdatePlcComponents(int fs_hz, size_t channels) virtual void UpdatePlcComponents(int fs_hz, size_t channels)
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
NetEqNetworkStatistics CurrentNetworkStatisticsInternal() const
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_; Clock* const clock_;
mutable Mutex mutex_; mutable Mutex mutex_;

View File

@ -312,16 +312,11 @@ void StatisticsCalculator::StoreWaitingTime(int waiting_time_ms) {
operations_and_state_.last_waiting_time_ms = waiting_time_ms; operations_and_state_.last_waiting_time_ms = waiting_time_ms;
} }
void StatisticsCalculator::GetNetworkStatistics(int fs_hz, void StatisticsCalculator::GetNetworkStatistics(size_t samples_per_packet,
size_t num_samples_in_buffers,
size_t samples_per_packet,
NetEqNetworkStatistics* stats) { NetEqNetworkStatistics* stats) {
RTC_DCHECK_GT(fs_hz, 0);
RTC_DCHECK(stats); RTC_DCHECK(stats);
stats->added_zero_samples = 0; stats->added_zero_samples = 0;
stats->current_buffer_size_ms =
static_cast<uint16_t>(num_samples_in_buffers * 1000 / fs_hz);
stats->packet_loss_rate = stats->packet_loss_rate =
CalculateQ14Ratio(lost_timestamps_, timestamps_since_last_report_); CalculateQ14Ratio(lost_timestamps_, timestamps_since_last_report_);

View File

@ -104,15 +104,11 @@ class StatisticsCalculator {
// period caused not by an actual packet loss, but by a delayed packet. // period caused not by an actual packet loss, but by a delayed packet.
virtual void LogDelayedPacketOutageEvent(int num_samples, int fs_hz); virtual void LogDelayedPacketOutageEvent(int num_samples, int fs_hz);
// Returns the current network statistics in |stats|. The current sample rate // Returns the current network statistics in |stats|. The number of samples
// is |fs_hz|, the total number of samples in packet buffer and sync buffer // per packet is |samples_per_packet|. The method does not populate
// yet to play out is |num_samples_in_buffers|, and the number of samples per
// packet is |samples_per_packet|. The method does not populate
// |preferred_buffer_size_ms|, |jitter_peaks_found| or |clockdrift_ppm|; use // |preferred_buffer_size_ms|, |jitter_peaks_found| or |clockdrift_ppm|; use
// the PopulateDelayManagerStats method for those. // the PopulateDelayManagerStats method for those.
void GetNetworkStatistics(int fs_hz, void GetNetworkStatistics(size_t samples_per_packet,
size_t num_samples_in_buffers,
size_t samples_per_packet,
NetEqNetworkStatistics* stats); NetEqNetworkStatistics* stats);
// Returns a copy of this class's lifetime statistics. These statistics are // Returns a copy of this class's lifetime statistics. These statistics are

View File

@ -70,14 +70,11 @@ TEST(StatisticsCalculator, ExpandedSamplesCorrection) {
constexpr int k10MsSamples = kSampleRateHz / 100; constexpr int k10MsSamples = kSampleRateHz / 100;
constexpr int kPacketSizeMs = 20; constexpr int kPacketSizeMs = 20;
constexpr size_t kSamplesPerPacket = kPacketSizeMs * kSampleRateHz / 1000; constexpr size_t kSamplesPerPacket = kPacketSizeMs * kSampleRateHz / 1000;
// Assume 2 packets in the buffer.
constexpr size_t kNumSamplesInBuffer = 2 * kSamplesPerPacket;
// Advance time by 10 ms. // Advance time by 10 ms.
stats.IncreaseCounter(k10MsSamples, kSampleRateHz); stats.IncreaseCounter(k10MsSamples, kSampleRateHz);
stats.GetNetworkStatistics(kSampleRateHz, kNumSamplesInBuffer, stats.GetNetworkStatistics(kSamplesPerPacket, &stats_output);
kSamplesPerPacket, &stats_output);
EXPECT_EQ(0u, stats_output.expand_rate); EXPECT_EQ(0u, stats_output.expand_rate);
EXPECT_EQ(0u, stats_output.speech_expand_rate); EXPECT_EQ(0u, stats_output.speech_expand_rate);
@ -86,8 +83,7 @@ TEST(StatisticsCalculator, ExpandedSamplesCorrection) {
stats.ExpandedVoiceSamplesCorrection(-100); stats.ExpandedVoiceSamplesCorrection(-100);
stats.ExpandedNoiseSamplesCorrection(-100); stats.ExpandedNoiseSamplesCorrection(-100);
stats.IncreaseCounter(k10MsSamples, kSampleRateHz); stats.IncreaseCounter(k10MsSamples, kSampleRateHz);
stats.GetNetworkStatistics(kSampleRateHz, kNumSamplesInBuffer, stats.GetNetworkStatistics(kSamplesPerPacket, &stats_output);
kSamplesPerPacket, &stats_output);
// Expect no change, since negative values are disallowed. // Expect no change, since negative values are disallowed.
EXPECT_EQ(0u, stats_output.expand_rate); EXPECT_EQ(0u, stats_output.expand_rate);
EXPECT_EQ(0u, stats_output.speech_expand_rate); EXPECT_EQ(0u, stats_output.speech_expand_rate);
@ -96,8 +92,7 @@ TEST(StatisticsCalculator, ExpandedSamplesCorrection) {
stats.ExpandedVoiceSamplesCorrection(50); stats.ExpandedVoiceSamplesCorrection(50);
stats.ExpandedNoiseSamplesCorrection(200); stats.ExpandedNoiseSamplesCorrection(200);
stats.IncreaseCounter(k10MsSamples, kSampleRateHz); stats.IncreaseCounter(k10MsSamples, kSampleRateHz);
stats.GetNetworkStatistics(kSampleRateHz, kNumSamplesInBuffer, stats.GetNetworkStatistics(kSamplesPerPacket, &stats_output);
kSamplesPerPacket, &stats_output);
// Calculate expected rates in Q14. Expand rate is noise + voice, while // Calculate expected rates in Q14. Expand rate is noise + voice, while
// speech expand rate is only voice. // speech expand rate is only voice.
EXPECT_EQ(((50u + 200u) << 14) / k10MsSamples, stats_output.expand_rate); EXPECT_EQ(((50u + 200u) << 14) / k10MsSamples, stats_output.expand_rate);

View File

@ -1955,7 +1955,8 @@ RTCStatsCollector::PrepareTransceiverStatsInfos_s_w() const {
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
for (const auto& entry : voice_stats) { for (const auto& entry : voice_stats) {
if (!entry.first->GetStats(entry.second.get())) { if (!entry.first->GetStats(entry.second.get(),
/*get_and_clear_legacy_stats=*/false)) {
RTC_LOG(LS_WARNING) << "Failed to get voice stats."; RTC_LOG(LS_WARNING) << "Failed to get voice stats.";
} }
} }

View File

@ -991,7 +991,8 @@ class VoiceMediaChannelStatsGatherer final : public MediaChannelStatsGatherer {
} }
bool GetStatsOnWorkerThread() override { bool GetStatsOnWorkerThread() override {
return voice_media_channel_->GetStats(&voice_media_info); return voice_media_channel_->GetStats(&voice_media_info,
/*get_and_clear_legacy_stats=*/true);
} }
void ExtractStats(StatsCollector* collector) const override { void ExtractStats(StatsCollector* collector) const override {

View File

@ -36,7 +36,8 @@ class FakeVoiceMediaChannelForStats : public cricket::FakeVoiceMediaChannel {
} }
// VoiceMediaChannel overrides. // VoiceMediaChannel overrides.
bool GetStats(cricket::VoiceMediaInfo* info) override { bool GetStats(cricket::VoiceMediaInfo* info,
bool get_and_clear_legacy_stats) override {
if (stats_) { if (stats_) {
*info = *stats_; *info = *stats_;
return true; return true;

View File

@ -212,7 +212,9 @@ void ReceiveAudioStream::Stop() {
AudioReceiveStream::Stats ReceiveAudioStream::GetStats() const { AudioReceiveStream::Stats ReceiveAudioStream::GetStats() const {
AudioReceiveStream::Stats result; AudioReceiveStream::Stats result;
receiver_->SendTask([&] { result = receive_stream_->GetStats(); }); receiver_->SendTask([&] {
result = receive_stream_->GetStats(/*get_and_clear_legacy_stats=*/true);
});
return result; return result;
} }

View File

@ -522,7 +522,8 @@ void VideoAnalyzer::PollStats() {
} }
if (audio_receive_stream_ != nullptr) { if (audio_receive_stream_ != nullptr) {
AudioReceiveStream::Stats receive_stats = audio_receive_stream_->GetStats(); AudioReceiveStream::Stats receive_stats =
audio_receive_stream_->GetStats(/*get_and_clear_legacy_stats=*/true);
audio_expand_rate_.AddSample(receive_stats.expand_rate); audio_expand_rate_.AddSample(receive_stats.expand_rate);
audio_accelerate_rate_.AddSample(receive_stats.accelerate_rate); audio_accelerate_rate_.AddSample(receive_stats.accelerate_rate);
audio_jitter_buffer_ms_.AddSample(receive_stats.jitter_buffer_ms); audio_jitter_buffer_ms_.AddSample(receive_stats.jitter_buffer_ms);