OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "gflags/gflags.h" | 13 #include "gflags/gflags.h" |
| 14 |
14 #include "webrtc/audio/test/low_bandwidth_audio_test.h" | 15 #include "webrtc/audio/test/low_bandwidth_audio_test.h" |
| 16 #include "webrtc/base/ptr_util.h" |
15 #include "webrtc/common_audio/wav_file.h" | 17 #include "webrtc/common_audio/wav_file.h" |
| 18 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 19 #include "webrtc/system_wrappers/include/sleep.h" |
| 20 #include "webrtc/test/field_trial.h" |
| 21 #include "webrtc/test/gmock.h" |
16 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
17 #include "webrtc/system_wrappers/include/sleep.h" | |
18 #include "webrtc/test/testsupport/fileutils.h" | 23 #include "webrtc/test/testsupport/fileutils.h" |
19 | 24 |
| 25 using ::testing::NiceMock; |
| 26 using ::testing::Invoke; |
| 27 using ::testing::_; |
20 | 28 |
21 DEFINE_int32(sample_rate_hz, 16000, | 29 DEFINE_int32(sample_rate_hz, 16000, |
22 "Sample rate (Hz) of the produced audio files."); | 30 "Sample rate (Hz) of the produced audio files."); |
23 | 31 |
24 DEFINE_bool(quick, false, | 32 DEFINE_bool(quick, false, |
25 "Don't do the full audio recording. " | 33 "Don't do the full audio recording. " |
26 "Used to quickly check that the test runs without crashing."); | 34 "Used to quickly check that the test runs without crashing."); |
27 | 35 |
28 namespace { | 36 namespace { |
29 | |
30 // Wait half a second between stopping sending and stopping receiving audio. | 37 // Wait half a second between stopping sending and stopping receiving audio. |
31 constexpr int kExtraRecordTimeMs = 500; | 38 constexpr int kExtraRecordTimeMs = 500; |
32 | 39 |
33 std::string FileSampleRateSuffix() { | 40 std::string FileSampleRateSuffix() { |
34 return std::to_string(FLAGS_sample_rate_hz / 1000); | 41 return std::to_string(FLAGS_sample_rate_hz / 1000); |
35 } | 42 } |
36 | 43 |
37 } // namespace | 44 } // namespace |
38 | 45 |
39 namespace webrtc { | 46 namespace webrtc { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 test::FakeAudioDevice* recv_audio_device) { | 87 test::FakeAudioDevice* recv_audio_device) { |
81 send_audio_device_ = send_audio_device; | 88 send_audio_device_ = send_audio_device; |
82 } | 89 } |
83 | 90 |
84 FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() { | 91 FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() { |
85 return FakeNetworkPipe::Config(); | 92 return FakeNetworkPipe::Config(); |
86 } | 93 } |
87 | 94 |
88 test::PacketTransport* AudioQualityTest::CreateSendTransport( | 95 test::PacketTransport* AudioQualityTest::CreateSendTransport( |
89 Call* sender_call) { | 96 Call* sender_call) { |
| 97 sender_call_ = sender_call; |
90 return new test::PacketTransport( | 98 return new test::PacketTransport( |
91 sender_call, this, test::PacketTransport::kSender, | 99 sender_call, this, test::PacketTransport::kSender, |
92 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); | 100 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); |
93 } | 101 } |
94 | 102 |
95 test::PacketTransport* AudioQualityTest::CreateReceiveTransport() { | 103 test::PacketTransport* AudioQualityTest::CreateReceiveTransport() { |
96 return new test::PacketTransport( | 104 return new test::PacketTransport( |
97 nullptr, this, test::PacketTransport::kReceiver, | 105 nullptr, this, test::PacketTransport::kReceiver, |
98 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); | 106 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); |
99 } | 107 } |
100 | 108 |
101 void AudioQualityTest::ModifyAudioConfigs( | 109 void AudioQualityTest::ModifyAudioConfigs( |
102 AudioSendStream::Config* send_config, | 110 AudioSendStream::Config* send_config, |
103 std::vector<AudioReceiveStream::Config>* receive_configs) { | 111 std::vector<AudioReceiveStream::Config>* receive_configs) { |
104 // Large bitrate by default. | 112 // Large bitrate by default. |
105 const webrtc::SdpAudioFormat kDefaultFormat("OPUS", 48000, 2, | 113 const webrtc::SdpAudioFormat kDefaultFormat("OPUS", 48000, 2, |
106 {{"stereo", "1"}}); | 114 {{"stereo", "1"}}); |
107 send_config->send_codec_spec = | 115 send_config->send_codec_spec = |
108 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( | 116 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
109 {test::CallTest::kAudioSendPayloadType, kDefaultFormat}); | 117 {test::CallTest::kAudioSendPayloadType, kDefaultFormat}); |
110 } | 118 } |
111 | 119 |
112 void AudioQualityTest::PerformTest() { | 120 void AudioQualityTest::PerformTest() { |
| 121 sender_call_->OnTransportOverheadChanged(webrtc::MediaType::AUDIO, 0); |
| 122 |
113 if (FLAGS_quick) { | 123 if (FLAGS_quick) { |
114 // Let the recording run for a small amount of time to check if it works. | 124 // Let the recording run for a small amount of time to check if it works. |
115 SleepMs(1000); | 125 SleepMs(1000); |
116 } else { | 126 } else { |
117 // Wait until the input audio file is done... | 127 // Wait until the input audio file is done... |
118 send_audio_device_->WaitForRecordingEnd(); | 128 send_audio_device_->WaitForRecordingEnd(); |
119 // and some extra time to account for network delay. | 129 // and some extra time to account for network delay. |
120 SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs); | 130 SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs); |
121 } | 131 } |
122 } | 132 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 pipe_config.queue_delay_ms = 400; | 171 pipe_config.queue_delay_ms = 400; |
162 return pipe_config; | 172 return pipe_config; |
163 } | 173 } |
164 }; | 174 }; |
165 | 175 |
166 TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { | 176 TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { |
167 Mobile2GNetworkTest test; | 177 Mobile2GNetworkTest test; |
168 RunBaseTest(&test); | 178 RunBaseTest(&test); |
169 } | 179 } |
170 | 180 |
| 181 class StatsPollTask : public rtc::QueuedTask { |
| 182 public: |
| 183 explicit StatsPollTask(Call* sender_call) : sender_call_(sender_call) {} |
| 184 |
| 185 private: |
| 186 bool Run() override { |
| 187 RTC_CHECK(sender_call_); |
| 188 Call::Stats call_stats = sender_call_->GetStats(); |
| 189 EXPECT_GT(call_stats.send_bandwidth_bps, 30000); |
| 190 rtc::TaskQueue::Current()->PostDelayedTask( |
| 191 std::unique_ptr<QueuedTask>(this), 100); |
| 192 return false; |
| 193 } |
| 194 Call* sender_call_; |
| 195 }; |
| 196 |
| 197 class NoBandwidthDropAfterDtx : public AudioQualityTest { |
| 198 public: |
| 199 NoBandwidthDropAfterDtx() : stats_poller_("stats poller task queue") {} |
| 200 |
| 201 void ModifyAudioConfigs( |
| 202 AudioSendStream::Config* send_config, |
| 203 std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 204 send_config->send_codec_spec = |
| 205 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
| 206 {test::CallTest::kAudioSendPayloadType, |
| 207 {"OPUS", |
| 208 48000, |
| 209 2, |
| 210 {{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}}}); |
| 211 |
| 212 send_config->min_bitrate_bps = 6000; |
| 213 send_config->max_bitrate_bps = 100000; |
| 214 send_config->rtp.extensions.push_back( |
| 215 RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 216 kTransportSequenceNumberExtensionId)); |
| 217 for (AudioReceiveStream::Config& recv_config : *receive_configs) { |
| 218 recv_config.rtp.transport_cc = true; |
| 219 recv_config.rtp.extensions = send_config->rtp.extensions; |
| 220 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc; |
| 221 } |
| 222 } |
| 223 |
| 224 std::string AudioInputFile() override { |
| 225 return test::ResourcePath("voice_engine/audio_dtx16", "wav"); |
| 226 } |
| 227 |
| 228 FakeNetworkPipe::Config GetNetworkPipeConfig() override { |
| 229 FakeNetworkPipe::Config pipe_config; |
| 230 pipe_config.link_capacity_kbps = 50; |
| 231 pipe_config.queue_length_packets = 1500; |
| 232 pipe_config.queue_delay_ms = 300; |
| 233 return pipe_config; |
| 234 } |
| 235 |
| 236 void PerformTest() override { |
| 237 stats_poller_.PostDelayedTask( |
| 238 std::unique_ptr<rtc::QueuedTask>(new StatsPollTask(sender_call_)), 100); |
| 239 AudioQualityTest::PerformTest(); |
| 240 } |
| 241 |
| 242 private: |
| 243 rtc::TaskQueue stats_poller_; |
| 244 }; |
| 245 |
| 246 TEST_F(LowBandwidthAudioTest, NoBandwidthDropAfterDtx) { |
| 247 webrtc::test::ScopedFieldTrials override_field_trials( |
| 248 "WebRTC-Audio-SendSideBwe/Enabled/" |
| 249 "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
| 250 NoBandwidthDropAfterDtx test; |
| 251 RunBaseTest(&test); |
| 252 } |
| 253 |
171 } // namespace test | 254 } // namespace test |
172 } // namespace webrtc | 255 } // namespace webrtc |
OLD | NEW |