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 "webrtc/audio/test/audio_end_to_end_test.h" |
12 | |
13 #include "webrtc/audio/test/low_bandwidth_audio_test.h" | |
14 #include "webrtc/common_audio/wav_file.h" | |
15 #include "webrtc/rtc_base/flags.h" | 12 #include "webrtc/rtc_base/flags.h" |
16 #include "webrtc/system_wrappers/include/sleep.h" | 13 #include "webrtc/system_wrappers/include/sleep.h" |
17 #include "webrtc/test/gtest.h" | |
18 #include "webrtc/test/testsupport/fileutils.h" | 14 #include "webrtc/test/testsupport/fileutils.h" |
19 | 15 |
20 | |
21 DEFINE_int(sample_rate_hz, 16000, | 16 DEFINE_int(sample_rate_hz, 16000, |
22 "Sample rate (Hz) of the produced audio files."); | 17 "Sample rate (Hz) of the produced audio files."); |
23 | 18 |
24 DEFINE_bool(quick, false, | 19 DEFINE_bool(quick, false, |
25 "Don't do the full audio recording. " | 20 "Don't do the full audio recording. " |
26 "Used to quickly check that the test runs without crashing."); | 21 "Used to quickly check that the test runs without crashing."); |
27 | 22 |
| 23 namespace webrtc { |
| 24 namespace test { |
28 namespace { | 25 namespace { |
29 | 26 |
30 // Wait half a second between stopping sending and stopping receiving audio. | |
31 constexpr int kExtraRecordTimeMs = 500; | |
32 | |
33 std::string FileSampleRateSuffix() { | 27 std::string FileSampleRateSuffix() { |
34 return std::to_string(FLAG_sample_rate_hz / 1000); | 28 return std::to_string(FLAG_sample_rate_hz / 1000); |
35 } | 29 } |
36 | 30 |
37 } // namespace | 31 class AudioQualityTest : public AudioEndToEndTest { |
| 32 public: |
| 33 AudioQualityTest() = default; |
38 | 34 |
39 namespace webrtc { | 35 private: |
40 namespace test { | 36 std::string AudioInputFile() const { |
| 37 return test::ResourcePath( |
| 38 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav"); |
| 39 } |
41 | 40 |
42 AudioQualityTest::AudioQualityTest() | 41 std::string AudioOutputFile() const { |
43 : EndToEndTest(CallTest::kDefaultTimeoutMs) {} | 42 const ::testing::TestInfo* const test_info = |
| 43 ::testing::UnitTest::GetInstance()->current_test_info(); |
| 44 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() + |
| 45 "_" + FileSampleRateSuffix() + ".wav"; |
| 46 } |
44 | 47 |
45 size_t AudioQualityTest::GetNumVideoStreams() const { | 48 std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override { |
46 return 0; | 49 return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile()); |
47 } | 50 } |
48 size_t AudioQualityTest::GetNumAudioStreams() const { | |
49 return 1; | |
50 } | |
51 size_t AudioQualityTest::GetNumFlexfecStreams() const { | |
52 return 0; | |
53 } | |
54 | 51 |
55 std::string AudioQualityTest::AudioInputFile() { | 52 std::unique_ptr<test::FakeAudioDevice::Renderer> CreateRenderer() override { |
56 return test::ResourcePath("voice_engine/audio_tiny" + FileSampleRateSuffix(), | 53 return test::FakeAudioDevice::CreateBoundedWavFileWriter( |
57 "wav"); | 54 AudioOutputFile(), FLAG_sample_rate_hz); |
58 } | 55 } |
59 | 56 |
60 std::string AudioQualityTest::AudioOutputFile() { | 57 void PerformTest() override { |
61 const ::testing::TestInfo* const test_info = | 58 if (FLAG_quick) { |
62 ::testing::UnitTest::GetInstance()->current_test_info(); | 59 // Let the recording run for a small amount of time to check if it works. |
63 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() + | 60 SleepMs(1000); |
64 "_" + FileSampleRateSuffix() + ".wav"; | 61 } else { |
65 } | 62 AudioEndToEndTest::PerformTest(); |
| 63 } |
| 64 } |
66 | 65 |
67 std::unique_ptr<test::FakeAudioDevice::Capturer> | 66 void OnStreamsStopped() override { |
68 AudioQualityTest::CreateCapturer() { | 67 const ::testing::TestInfo* const test_info = |
69 return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile()); | 68 ::testing::UnitTest::GetInstance()->current_test_info(); |
70 } | |
71 | 69 |
72 std::unique_ptr<test::FakeAudioDevice::Renderer> | 70 // Output information about the input and output audio files so that further |
73 AudioQualityTest::CreateRenderer() { | 71 // processing can be done by an external process. |
74 return test::FakeAudioDevice::CreateBoundedWavFileWriter( | 72 printf("TEST %s %s %s\n", test_info->name(), |
75 AudioOutputFile(), FLAG_sample_rate_hz); | 73 AudioInputFile().c_str(), AudioOutputFile().c_str()); |
76 } | |
77 | |
78 void AudioQualityTest::OnFakeAudioDevicesCreated( | |
79 test::FakeAudioDevice* send_audio_device, | |
80 test::FakeAudioDevice* recv_audio_device) { | |
81 send_audio_device_ = send_audio_device; | |
82 } | |
83 | |
84 FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() { | |
85 return FakeNetworkPipe::Config(); | |
86 } | |
87 | |
88 test::PacketTransport* AudioQualityTest::CreateSendTransport( | |
89 SingleThreadedTaskQueueForTesting* task_queue, | |
90 Call* sender_call) { | |
91 return new test::PacketTransport( | |
92 task_queue, sender_call, this, test::PacketTransport::kSender, | |
93 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); | |
94 } | |
95 | |
96 test::PacketTransport* AudioQualityTest::CreateReceiveTransport( | |
97 SingleThreadedTaskQueueForTesting* task_queue) { | |
98 return new test::PacketTransport( | |
99 task_queue, nullptr, this, test::PacketTransport::kReceiver, | |
100 test::CallTest::payload_type_map_, GetNetworkPipeConfig()); | |
101 } | |
102 | |
103 void AudioQualityTest::ModifyAudioConfigs( | |
104 AudioSendStream::Config* send_config, | |
105 std::vector<AudioReceiveStream::Config>* receive_configs) { | |
106 // Large bitrate by default. | |
107 const webrtc::SdpAudioFormat kDefaultFormat("OPUS", 48000, 2, | |
108 {{"stereo", "1"}}); | |
109 send_config->send_codec_spec = | |
110 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( | |
111 {test::CallTest::kAudioSendPayloadType, kDefaultFormat}); | |
112 } | |
113 | |
114 void AudioQualityTest::PerformTest() { | |
115 if (FLAG_quick) { | |
116 // Let the recording run for a small amount of time to check if it works. | |
117 SleepMs(1000); | |
118 } else { | |
119 // Wait until the input audio file is done... | |
120 send_audio_device_->WaitForRecordingEnd(); | |
121 // and some extra time to account for network delay. | |
122 SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs); | |
123 } | 74 } |
124 } | 75 }; |
125 | |
126 void AudioQualityTest::OnTestFinished() { | |
127 const ::testing::TestInfo* const test_info = | |
128 ::testing::UnitTest::GetInstance()->current_test_info(); | |
129 | |
130 // Output information about the input and output audio files so that further | |
131 // processing can be done by an external process. | |
132 printf("TEST %s %s %s\n", test_info->name(), | |
133 AudioInputFile().c_str(), AudioOutputFile().c_str()); | |
134 } | |
135 | |
136 | |
137 using LowBandwidthAudioTest = CallTest; | |
138 | |
139 TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) { | |
140 AudioQualityTest test; | |
141 RunBaseTest(&test); | |
142 } | |
143 | |
144 | 76 |
145 class Mobile2GNetworkTest : public AudioQualityTest { | 77 class Mobile2GNetworkTest : public AudioQualityTest { |
146 void ModifyAudioConfigs(AudioSendStream::Config* send_config, | 78 void ModifyAudioConfigs(AudioSendStream::Config* send_config, |
147 std::vector<AudioReceiveStream::Config>* receive_configs) override { | 79 std::vector<AudioReceiveStream::Config>* receive_configs) override { |
148 send_config->send_codec_spec = | 80 send_config->send_codec_spec = |
149 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( | 81 rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
150 {test::CallTest::kAudioSendPayloadType, | 82 {test::CallTest::kAudioSendPayloadType, |
151 {"OPUS", | 83 {"OPUS", |
152 48000, | 84 48000, |
153 2, | 85 2, |
154 {{"maxaveragebitrate", "6000"}, | 86 {{"maxaveragebitrate", "6000"}, |
155 {"ptime", "60"}, | 87 {"ptime", "60"}, |
156 {"stereo", "1"}}}}); | 88 {"stereo", "1"}}}}); |
157 } | 89 } |
158 | 90 |
159 FakeNetworkPipe::Config GetNetworkPipeConfig() override { | 91 FakeNetworkPipe::Config GetNetworkPipeConfig() const override { |
160 FakeNetworkPipe::Config pipe_config; | 92 FakeNetworkPipe::Config pipe_config; |
161 pipe_config.link_capacity_kbps = 12; | 93 pipe_config.link_capacity_kbps = 12; |
162 pipe_config.queue_length_packets = 1500; | 94 pipe_config.queue_length_packets = 1500; |
163 pipe_config.queue_delay_ms = 400; | 95 pipe_config.queue_delay_ms = 400; |
164 return pipe_config; | 96 return pipe_config; |
165 } | 97 } |
166 }; | 98 }; |
| 99 } // namespace |
| 100 |
| 101 using LowBandwidthAudioTest = CallTest; |
| 102 |
| 103 TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) { |
| 104 AudioQualityTest test; |
| 105 RunBaseTest(&test); |
| 106 } |
167 | 107 |
168 TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { | 108 TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { |
169 Mobile2GNetworkTest test; | 109 Mobile2GNetworkTest test; |
170 RunBaseTest(&test); | 110 RunBaseTest(&test); |
171 } | 111 } |
172 | |
173 } // namespace test | 112 } // namespace test |
174 } // namespace webrtc | 113 } // namespace webrtc |
OLD | NEW |