• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "audio/test/audio_end_to_end_test.h"
12 #include "rtc_base/numerics/safe_compare.h"
13 #include "system_wrappers/include/sleep.h"
14 #include "test/gtest.h"
15 
16 namespace webrtc {
17 namespace test {
18 namespace {
19 
IsNear(int reference,int v)20 bool IsNear(int reference, int v) {
21   // Margin is 10%.
22   const int error = reference / 10 + 1;
23   return std::abs(reference - v) <= error;
24 }
25 
26 class NoLossTest : public AudioEndToEndTest {
27  public:
28   const int kTestDurationMs = 8000;
29   const int kBytesSent = 69351;
30   const int32_t kPacketsSent = 400;
31   const int64_t kRttMs = 100;
32 
33   NoLossTest() = default;
34 
GetNetworkPipeConfig() const35   BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
36     BuiltInNetworkBehaviorConfig pipe_config;
37     pipe_config.queue_delay_ms = kRttMs / 2;
38     return pipe_config;
39   }
40 
PerformTest()41   void PerformTest() override {
42     SleepMs(kTestDurationMs);
43     send_audio_device()->StopRecording();
44     AudioEndToEndTest::PerformTest();
45   }
46 
OnStreamsStopped()47   void OnStreamsStopped() override {
48     AudioSendStream::Stats send_stats = send_stream()->GetStats();
49     EXPECT_PRED2(IsNear, kBytesSent, send_stats.payload_bytes_sent);
50     EXPECT_PRED2(IsNear, kPacketsSent, send_stats.packets_sent);
51     EXPECT_EQ(0, send_stats.packets_lost);
52     EXPECT_EQ(0.0f, send_stats.fraction_lost);
53     EXPECT_EQ("opus", send_stats.codec_name);
54     // send_stats.jitter_ms
55     EXPECT_PRED2(IsNear, kRttMs, send_stats.rtt_ms);
56     // Send level is 0 because it is cleared in TransmitMixer::StopSend().
57     EXPECT_EQ(0, send_stats.audio_level);
58     // send_stats.total_input_energy
59     // send_stats.total_input_duration
60     EXPECT_FALSE(send_stats.apm_statistics.delay_median_ms);
61     EXPECT_FALSE(send_stats.apm_statistics.delay_standard_deviation_ms);
62     EXPECT_FALSE(send_stats.apm_statistics.echo_return_loss);
63     EXPECT_FALSE(send_stats.apm_statistics.echo_return_loss_enhancement);
64     EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood);
65     EXPECT_FALSE(send_stats.apm_statistics.residual_echo_likelihood_recent_max);
66 
67     AudioReceiveStreamInterface::Stats recv_stats =
68         receive_stream()->GetStats(/*get_and_clear_legacy_stats=*/true);
69     EXPECT_PRED2(IsNear, kBytesSent, recv_stats.payload_bytes_rcvd);
70     EXPECT_PRED2(IsNear, kPacketsSent, recv_stats.packets_rcvd);
71     EXPECT_EQ(0, recv_stats.packets_lost);
72     EXPECT_EQ("opus", send_stats.codec_name);
73     // recv_stats.jitter_ms
74     // recv_stats.jitter_buffer_ms
75     EXPECT_EQ(20u, recv_stats.jitter_buffer_preferred_ms);
76     // recv_stats.delay_estimate_ms
77     // Receive level is 0 because it is cleared in Channel::StopPlayout().
78     EXPECT_EQ(0, recv_stats.audio_level);
79     // recv_stats.total_output_energy
80     // recv_stats.total_samples_received
81     // recv_stats.total_output_duration
82     // recv_stats.concealed_samples
83     // recv_stats.expand_rate
84     // recv_stats.speech_expand_rate
85     EXPECT_EQ(0.0, recv_stats.secondary_decoded_rate);
86     EXPECT_EQ(0.0, recv_stats.secondary_discarded_rate);
87     EXPECT_EQ(0.0, recv_stats.accelerate_rate);
88     EXPECT_EQ(0.0, recv_stats.preemptive_expand_rate);
89     EXPECT_EQ(0, recv_stats.decoding_calls_to_silence_generator);
90     // recv_stats.decoding_calls_to_neteq
91     // recv_stats.decoding_normal
92     // recv_stats.decoding_plc
93     EXPECT_EQ(0, recv_stats.decoding_cng);
94     // recv_stats.decoding_plc_cng
95     // recv_stats.decoding_muted_output
96     // Capture start time is -1 because we do not have an associated send stream
97     // on the receiver side.
98     EXPECT_EQ(-1, recv_stats.capture_start_ntp_time_ms);
99 
100     // Match these stats between caller and receiver.
101     EXPECT_EQ(send_stats.local_ssrc, recv_stats.remote_ssrc);
102     EXPECT_EQ(*send_stats.codec_payload_type, *recv_stats.codec_payload_type);
103   }
104 };
105 }  // namespace
106 
107 using AudioStatsTest = CallTest;
108 
TEST_F(AudioStatsTest,DISABLED_NoLoss)109 TEST_F(AudioStatsTest, DISABLED_NoLoss) {
110   NoLossTest test;
111   RunBaseTest(&test);
112 }
113 
114 }  // namespace test
115 }  // namespace webrtc
116