tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "audio/test/audio_bwe_integration_test.h" |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 12 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 13 | #include "absl/memory/memory.h" |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 14 | #include "call/fake_network_pipe.h" |
| 15 | #include "call/simulated_network.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "common_audio/wav_file.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "system_wrappers/include/sleep.h" |
| 18 | #include "test/field_trial.h" |
| 19 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 20 | #include "test/testsupport/file_utils.h" |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
| 25 | namespace { |
| 26 | // Wait a second between stopping sending and stopping receiving audio. |
| 27 | constexpr int kExtraProcessTimeMs = 1000; |
| 28 | } // namespace |
| 29 | |
| 30 | AudioBweTest::AudioBweTest() : EndToEndTest(CallTest::kDefaultTimeoutMs) {} |
| 31 | |
| 32 | size_t AudioBweTest::GetNumVideoStreams() const { |
| 33 | return 0; |
| 34 | } |
| 35 | size_t AudioBweTest::GetNumAudioStreams() const { |
| 36 | return 1; |
| 37 | } |
| 38 | size_t AudioBweTest::GetNumFlexfecStreams() const { |
| 39 | return 0; |
| 40 | } |
| 41 | |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 42 | std::unique_ptr<TestAudioDeviceModule::Capturer> |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 43 | AudioBweTest::CreateCapturer() { |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 44 | return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile()); |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void AudioBweTest::OnFakeAudioDevicesCreated( |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 48 | TestAudioDeviceModule* send_audio_device, |
| 49 | TestAudioDeviceModule* recv_audio_device) { |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 50 | send_audio_device_ = send_audio_device; |
| 51 | } |
| 52 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 53 | test::PacketTransport* AudioBweTest::CreateSendTransport( |
| 54 | SingleThreadedTaskQueueForTesting* task_queue, |
| 55 | Call* sender_call) { |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 56 | return new test::PacketTransport( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 57 | task_queue, sender_call, this, test::PacketTransport::kSender, |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 58 | test::CallTest::payload_type_map_, |
| 59 | absl::make_unique<FakeNetworkPipe>( |
| 60 | Clock::GetRealTimeClock(), |
| 61 | absl::make_unique<SimulatedNetwork>(GetNetworkPipeConfig()))); |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 62 | } |
| 63 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 64 | test::PacketTransport* AudioBweTest::CreateReceiveTransport( |
| 65 | SingleThreadedTaskQueueForTesting* task_queue) { |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 66 | return new test::PacketTransport( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 67 | task_queue, nullptr, this, test::PacketTransport::kReceiver, |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 68 | test::CallTest::payload_type_map_, |
| 69 | absl::make_unique<FakeNetworkPipe>( |
| 70 | Clock::GetRealTimeClock(), |
| 71 | absl::make_unique<SimulatedNetwork>(GetNetworkPipeConfig()))); |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void AudioBweTest::PerformTest() { |
| 75 | send_audio_device_->WaitForRecordingEnd(); |
| 76 | SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraProcessTimeMs); |
| 77 | } |
| 78 | |
| 79 | class StatsPollTask : public rtc::QueuedTask { |
| 80 | public: |
| 81 | explicit StatsPollTask(Call* sender_call) : sender_call_(sender_call) {} |
| 82 | |
| 83 | private: |
| 84 | bool Run() override { |
| 85 | RTC_CHECK(sender_call_); |
| 86 | Call::Stats call_stats = sender_call_->GetStats(); |
| 87 | EXPECT_GT(call_stats.send_bandwidth_bps, 25000); |
| 88 | rtc::TaskQueue::Current()->PostDelayedTask( |
| 89 | std::unique_ptr<QueuedTask>(this), 100); |
| 90 | return false; |
| 91 | } |
| 92 | Call* sender_call_; |
| 93 | }; |
| 94 | |
| 95 | class NoBandwidthDropAfterDtx : public AudioBweTest { |
| 96 | public: |
| 97 | NoBandwidthDropAfterDtx() |
| 98 | : sender_call_(nullptr), stats_poller_("stats poller task queue") {} |
| 99 | |
| 100 | void ModifyAudioConfigs( |
| 101 | AudioSendStream::Config* send_config, |
| 102 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
Oskar Sundbom | 2707fb2 | 2017-11-16 10:57:35 +0100 | [diff] [blame] | 103 | send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
| 104 | test::CallTest::kAudioSendPayloadType, |
| 105 | {"OPUS", |
| 106 | 48000, |
| 107 | 2, |
| 108 | {{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}}); |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 109 | |
| 110 | send_config->min_bitrate_bps = 6000; |
| 111 | send_config->max_bitrate_bps = 100000; |
| 112 | send_config->rtp.extensions.push_back( |
| 113 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 114 | kTransportSequenceNumberExtensionId)); |
| 115 | for (AudioReceiveStream::Config& recv_config : *receive_configs) { |
| 116 | recv_config.rtp.transport_cc = true; |
| 117 | recv_config.rtp.extensions = send_config->rtp.extensions; |
| 118 | recv_config.rtp.remote_ssrc = send_config->rtp.ssrc; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | std::string AudioInputFile() override { |
| 123 | return test::ResourcePath("voice_engine/audio_dtx16", "wav"); |
| 124 | } |
| 125 | |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 126 | BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() override { |
| 127 | BuiltInNetworkBehaviorConfig pipe_config; |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 128 | pipe_config.link_capacity_kbps = 50; |
| 129 | pipe_config.queue_length_packets = 1500; |
| 130 | pipe_config.queue_delay_ms = 300; |
| 131 | return pipe_config; |
| 132 | } |
| 133 | |
| 134 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 135 | sender_call_ = sender_call; |
| 136 | } |
| 137 | |
| 138 | void PerformTest() override { |
| 139 | stats_poller_.PostDelayedTask( |
| 140 | std::unique_ptr<rtc::QueuedTask>(new StatsPollTask(sender_call_)), 100); |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 141 | sender_call_->OnAudioTransportOverheadChanged(0); |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 142 | AudioBweTest::PerformTest(); |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | Call* sender_call_; |
| 147 | rtc::TaskQueue stats_poller_; |
| 148 | }; |
| 149 | |
| 150 | using AudioBweIntegrationTest = CallTest; |
| 151 | |
tschumim | e76f55e | 2017-07-19 07:52:47 -0700 | [diff] [blame] | 152 | // TODO(tschumim): This test is flaky when run on android and mac. Re-enable the |
| 153 | // test for when the issue is fixed. |
| 154 | TEST_F(AudioBweIntegrationTest, DISABLED_NoBandwidthDropAfterDtx) { |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 155 | webrtc::test::ScopedFieldTrials override_field_trials( |
| 156 | "WebRTC-Audio-SendSideBwe/Enabled/" |
| 157 | "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
| 158 | NoBandwidthDropAfterDtx test; |
| 159 | RunBaseTest(&test); |
| 160 | } |
| 161 | |
| 162 | } // namespace test |
| 163 | } // namespace webrtc |