xref: /aosp_15_r20/external/webrtc/audio/test/non_sender_rtt_test.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2021 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 "system_wrappers/include/sleep.h"
13 #include "test/gtest.h"
14 
15 namespace webrtc {
16 namespace test {
17 
18 using NonSenderRttTest = CallTest;
19 
TEST_F(NonSenderRttTest,NonSenderRttStats)20 TEST_F(NonSenderRttTest, NonSenderRttStats) {
21   class NonSenderRttTest : public AudioEndToEndTest {
22    public:
23     const int kTestDurationMs = 10000;
24     const int64_t kRttMs = 30;
25 
26     BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
27       BuiltInNetworkBehaviorConfig pipe_config;
28       pipe_config.queue_delay_ms = kRttMs / 2;
29       return pipe_config;
30     }
31 
32     void ModifyAudioConfigs(AudioSendStream::Config* send_config,
33                             std::vector<AudioReceiveStreamInterface::Config>*
34                                 receive_configs) override {
35       ASSERT_EQ(receive_configs->size(), 1U);
36       (*receive_configs)[0].enable_non_sender_rtt = true;
37       AudioEndToEndTest::ModifyAudioConfigs(send_config, receive_configs);
38       send_config->send_codec_spec->enable_non_sender_rtt = true;
39     }
40 
41     void PerformTest() override { SleepMs(kTestDurationMs); }
42 
43     void OnStreamsStopped() override {
44       AudioReceiveStreamInterface::Stats recv_stats =
45           receive_stream()->GetStats(/*get_and_clear_legacy_stats=*/true);
46       EXPECT_GT(recv_stats.round_trip_time_measurements, 0);
47       ASSERT_TRUE(recv_stats.round_trip_time.has_value());
48       EXPECT_GT(recv_stats.round_trip_time->ms(), 0);
49       EXPECT_GE(recv_stats.total_round_trip_time.ms(),
50                 recv_stats.round_trip_time->ms());
51     }
52   } test;
53 
54   RunBaseTest(&test);
55 }
56 
57 }  // namespace test
58 }  // namespace webrtc
59