audio_stats_test.cc (4672B)
1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <cstdint> 12 #include <cstdlib> 13 14 #include "api/test/simulated_network.h" 15 #include "audio/test/audio_end_to_end_test.h" 16 #include "call/audio_receive_stream.h" 17 #include "call/audio_send_stream.h" 18 #include "rtc_base/thread.h" 19 #include "test/call_test.h" 20 #include "test/gtest.h" 21 22 namespace webrtc { 23 namespace test { 24 namespace { 25 26 // Wait half a second between stopping sending and stopping receiving audio. 27 constexpr int kExtraRecordTimeMs = 500; 28 29 bool IsNear(int reference, int v) { 30 // Margin is 10%. 31 const int error = reference / 10 + 1; 32 return std::abs(reference - v) <= error; 33 } 34 35 class NoLossTest : public AudioEndToEndTest { 36 public: 37 const int kTestDurationMs = 8000; 38 const int kBytesSent = 69351; 39 const int32_t kPacketsSent = 400; 40 const int64_t kRttMs = 100; 41 42 NoLossTest() = default; 43 44 BuiltInNetworkBehaviorConfig GetSendTransportConfig() const override { 45 BuiltInNetworkBehaviorConfig pipe_config; 46 pipe_config.queue_delay_ms = kRttMs / 2; 47 return pipe_config; 48 } 49 50 void PerformTest() override { 51 Thread::SleepMs(kTestDurationMs); 52 send_audio_device()->StopRecording(); 53 // and some extra time to account for network delay. 54 Thread::SleepMs(GetSendTransportConfig().queue_delay_ms + 55 kExtraRecordTimeMs); 56 } 57 58 void OnStreamsStopped() override { 59 AudioSendStream::Stats send_stats = send_stream()->GetStats(); 60 EXPECT_PRED2(IsNear, kBytesSent, send_stats.payload_bytes_sent); 61 EXPECT_PRED2(IsNear, kPacketsSent, send_stats.packets_sent); 62 EXPECT_EQ(0, send_stats.packets_lost); 63 EXPECT_EQ(0.0f, send_stats.fraction_lost); 64 EXPECT_EQ("opus", send_stats.codec_name); 65 // send_stats.jitter_ms 66 EXPECT_PRED2(IsNear, kRttMs, send_stats.rtt_ms); 67 // Send level is 0 because it is cleared in TransmitMixer::StopSend(). 68 EXPECT_EQ(0, send_stats.audio_level); 69 // send_stats.total_input_energy 70 // send_stats.total_input_duration 71 EXPECT_FALSE(send_stats.apm_statistics.delay_median_ms); 72 EXPECT_FALSE(send_stats.apm_statistics.delay_standard_deviation_ms); 73 EXPECT_FALSE(send_stats.apm_statistics.echo_return_loss); 74 EXPECT_FALSE(send_stats.apm_statistics.echo_return_loss_enhancement); 75 EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood); 76 EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood_recent_max); 77 78 AudioReceiveStreamInterface::Stats recv_stats = 79 receive_stream()->GetStats(/*get_and_clear_legacy_stats=*/true); 80 EXPECT_PRED2(IsNear, kBytesSent, recv_stats.payload_bytes_received); 81 EXPECT_PRED2(IsNear, kPacketsSent, recv_stats.packets_received); 82 EXPECT_EQ(0, recv_stats.packets_lost); 83 EXPECT_EQ("opus", send_stats.codec_name); 84 // recv_stats.jitter_ms 85 // recv_stats.jitter_buffer_ms 86 EXPECT_EQ(20u, recv_stats.jitter_buffer_preferred_ms); 87 // recv_stats.delay_estimate_ms 88 // Receive level is 0 because it is cleared in Channel::StopPlayout(). 89 EXPECT_EQ(0, recv_stats.audio_level); 90 // recv_stats.total_output_energy 91 // recv_stats.total_samples_received 92 // recv_stats.total_output_duration 93 // recv_stats.concealed_samples 94 // recv_stats.expand_rate 95 // recv_stats.speech_expand_rate 96 EXPECT_EQ(0.0, recv_stats.secondary_decoded_rate); 97 EXPECT_EQ(0.0, recv_stats.secondary_discarded_rate); 98 EXPECT_EQ(0.0, recv_stats.accelerate_rate); 99 EXPECT_EQ(0.0, recv_stats.preemptive_expand_rate); 100 EXPECT_EQ(0, recv_stats.decoding_calls_to_silence_generator); 101 // recv_stats.decoding_calls_to_neteq 102 // recv_stats.decoding_normal 103 // recv_stats.decoding_plc 104 EXPECT_EQ(0, recv_stats.decoding_cng); 105 // recv_stats.decoding_plc_cng 106 // recv_stats.decoding_muted_output 107 // Capture start time is -1 because we do not have an associated send stream 108 // on the receiver side. 109 EXPECT_EQ(-1, recv_stats.capture_start_ntp_time_ms); 110 111 // Match these stats between caller and receiver. 112 EXPECT_EQ(send_stats.local_ssrc, recv_stats.remote_ssrc); 113 EXPECT_EQ(*send_stats.codec_payload_type, *recv_stats.codec_payload_type); 114 } 115 }; 116 } // namespace 117 118 using AudioStatsTest = CallTest; 119 120 TEST_F(AudioStatsTest, DISABLED_NoLoss) { 121 NoLossTest test; 122 RunBaseTest(&test); 123 } 124 125 } // namespace test 126 } // namespace webrtc