xref: /aosp_15_r20/external/webrtc/audio/test/audio_bwe_integration_test.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_bwe_integration_test.h"
12 
13 #include <memory>
14 
15 #include "absl/functional/any_invocable.h"
16 #include "api/task_queue/task_queue_base.h"
17 #include "call/fake_network_pipe.h"
18 #include "call/simulated_network.h"
19 #include "common_audio/wav_file.h"
20 #include "rtc_base/task_queue_for_test.h"
21 #include "system_wrappers/include/sleep.h"
22 #include "test/field_trial.h"
23 #include "test/gtest.h"
24 #include "test/testsupport/file_utils.h"
25 
26 namespace webrtc {
27 namespace test {
28 
29 namespace {
30 enum : int {  // The first valid value is 1.
31   kTransportSequenceNumberExtensionId = 1,
32 };
33 
34 // Wait a second between stopping sending and stopping receiving audio.
35 constexpr int kExtraProcessTimeMs = 1000;
36 }  // namespace
37 
AudioBweTest()38 AudioBweTest::AudioBweTest() : EndToEndTest(CallTest::kDefaultTimeout) {}
39 
GetNumVideoStreams() const40 size_t AudioBweTest::GetNumVideoStreams() const {
41   return 0;
42 }
GetNumAudioStreams() const43 size_t AudioBweTest::GetNumAudioStreams() const {
44   return 1;
45 }
GetNumFlexfecStreams() const46 size_t AudioBweTest::GetNumFlexfecStreams() const {
47   return 0;
48 }
49 
50 std::unique_ptr<TestAudioDeviceModule::Capturer>
CreateCapturer()51 AudioBweTest::CreateCapturer() {
52   return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
53 }
54 
OnFakeAudioDevicesCreated(TestAudioDeviceModule * send_audio_device,TestAudioDeviceModule * recv_audio_device)55 void AudioBweTest::OnFakeAudioDevicesCreated(
56     TestAudioDeviceModule* send_audio_device,
57     TestAudioDeviceModule* recv_audio_device) {
58   send_audio_device_ = send_audio_device;
59 }
60 
CreateSendTransport(TaskQueueBase * task_queue,Call * sender_call)61 std::unique_ptr<test::PacketTransport> AudioBweTest::CreateSendTransport(
62     TaskQueueBase* task_queue,
63     Call* sender_call) {
64   return std::make_unique<test::PacketTransport>(
65       task_queue, sender_call, this, test::PacketTransport::kSender,
66       test::CallTest::payload_type_map_,
67       std::make_unique<FakeNetworkPipe>(
68           Clock::GetRealTimeClock(),
69           std::make_unique<SimulatedNetwork>(GetNetworkPipeConfig())));
70 }
71 
CreateReceiveTransport(TaskQueueBase * task_queue)72 std::unique_ptr<test::PacketTransport> AudioBweTest::CreateReceiveTransport(
73     TaskQueueBase* task_queue) {
74   return std::make_unique<test::PacketTransport>(
75       task_queue, nullptr, this, test::PacketTransport::kReceiver,
76       test::CallTest::payload_type_map_,
77       std::make_unique<FakeNetworkPipe>(
78           Clock::GetRealTimeClock(),
79           std::make_unique<SimulatedNetwork>(GetNetworkPipeConfig())));
80 }
81 
PerformTest()82 void AudioBweTest::PerformTest() {
83   send_audio_device_->WaitForRecordingEnd();
84   SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraProcessTimeMs);
85 }
86 
StatsPollTask(Call * sender_call)87 absl::AnyInvocable<void() &&> StatsPollTask(Call* sender_call) {
88   RTC_CHECK(sender_call);
89   return [sender_call] {
90     Call::Stats call_stats = sender_call->GetStats();
91     EXPECT_GT(call_stats.send_bandwidth_bps, 25000);
92     TaskQueueBase::Current()->PostDelayedTask(StatsPollTask(sender_call),
93                                               TimeDelta::Millis(100));
94   };
95 }
96 
97 class NoBandwidthDropAfterDtx : public AudioBweTest {
98  public:
NoBandwidthDropAfterDtx()99   NoBandwidthDropAfterDtx()
100       : sender_call_(nullptr), stats_poller_("stats poller task queue") {}
101 
ModifyAudioConfigs(AudioSendStream::Config * send_config,std::vector<AudioReceiveStreamInterface::Config> * receive_configs)102   void ModifyAudioConfigs(AudioSendStream::Config* send_config,
103                           std::vector<AudioReceiveStreamInterface::Config>*
104                               receive_configs) override {
105     send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
106         test::CallTest::kAudioSendPayloadType,
107         {"OPUS",
108          48000,
109          2,
110          {{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}});
111 
112     send_config->min_bitrate_bps = 6000;
113     send_config->max_bitrate_bps = 100000;
114     send_config->rtp.extensions.push_back(
115         RtpExtension(RtpExtension::kTransportSequenceNumberUri,
116                      kTransportSequenceNumberExtensionId));
117     for (AudioReceiveStreamInterface::Config& recv_config : *receive_configs) {
118       recv_config.rtp.transport_cc = true;
119       recv_config.rtp.extensions = send_config->rtp.extensions;
120       recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
121     }
122   }
123 
AudioInputFile()124   std::string AudioInputFile() override {
125     return test::ResourcePath("voice_engine/audio_dtx16", "wav");
126   }
127 
GetNetworkPipeConfig()128   BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() override {
129     BuiltInNetworkBehaviorConfig pipe_config;
130     pipe_config.link_capacity_kbps = 50;
131     pipe_config.queue_length_packets = 1500;
132     pipe_config.queue_delay_ms = 300;
133     return pipe_config;
134   }
135 
OnCallsCreated(Call * sender_call,Call * receiver_call)136   void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
137     sender_call_ = sender_call;
138   }
139 
PerformTest()140   void PerformTest() override {
141     stats_poller_.PostDelayedTask(StatsPollTask(sender_call_),
142                                   TimeDelta::Millis(100));
143     sender_call_->OnAudioTransportOverheadChanged(0);
144     AudioBweTest::PerformTest();
145   }
146 
147  private:
148   Call* sender_call_;
149   TaskQueueForTest stats_poller_;
150 };
151 
152 using AudioBweIntegrationTest = CallTest;
153 
154 // TODO(tschumim): This test is flaky when run on android and mac. Re-enable the
155 // test for when the issue is fixed.
TEST_F(AudioBweIntegrationTest,DISABLED_NoBandwidthDropAfterDtx)156 TEST_F(AudioBweIntegrationTest, DISABLED_NoBandwidthDropAfterDtx) {
157   NoBandwidthDropAfterDtx test;
158   RunBaseTest(&test);
159 }
160 
161 }  // namespace test
162 }  // namespace webrtc
163