blob: ea0cdf024ca23fd724eb61506972cf9d404ed758 [file] [log] [blame]
kjellander8f8d1a02017-03-06 04:01:16 -08001/*
oprypin92220ff2017-03-23 03:40:03 -07002 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
kjellander8f8d1a02017-03-06 04:01:16 -08003 *
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
oprypin92220ff2017-03-23 03:40:03 -070011#include <algorithm>
kjellander8f8d1a02017-03-06 04:01:16 -080012
oprypin92220ff2017-03-23 03:40:03 -070013#include "webrtc/audio/test/low_bandwidth_audio_test.h"
14#include "webrtc/common_audio/wav_file.h"
oprypin9b2f20c2017-08-29 05:51:57 -070015#include "webrtc/rtc_base/flags.h"
oprypin92220ff2017-03-23 03:40:03 -070016#include "webrtc/system_wrappers/include/sleep.h"
oprypin9b2f20c2017-08-29 05:51:57 -070017#include "webrtc/test/gtest.h"
oprypin92220ff2017-03-23 03:40:03 -070018#include "webrtc/test/testsupport/fileutils.h"
19
oprypinf2501002017-04-12 05:00:56 -070020
oprypin9b2f20c2017-08-29 05:51:57 -070021DEFINE_int(sample_rate_hz, 16000,
22 "Sample rate (Hz) of the produced audio files.");
oprypinf2501002017-04-12 05:00:56 -070023
oprypin76a1ce72017-05-04 03:06:18 -070024DEFINE_bool(quick, false,
25 "Don't do the full audio recording. "
26 "Used to quickly check that the test runs without crashing.");
27
oprypin92220ff2017-03-23 03:40:03 -070028namespace {
oprypinf2501002017-04-12 05:00:56 -070029
oprypin92220ff2017-03-23 03:40:03 -070030// Wait half a second between stopping sending and stopping receiving audio.
31constexpr int kExtraRecordTimeMs = 500;
32
oprypinf2501002017-04-12 05:00:56 -070033std::string FileSampleRateSuffix() {
oprypin9b2f20c2017-08-29 05:51:57 -070034 return std::to_string(FLAG_sample_rate_hz / 1000);
oprypinf2501002017-04-12 05:00:56 -070035}
36
minyue20c84cc2017-04-10 16:57:57 -070037} // namespace
oprypin92220ff2017-03-23 03:40:03 -070038
39namespace webrtc {
40namespace test {
41
42AudioQualityTest::AudioQualityTest()
43 : EndToEndTest(CallTest::kDefaultTimeoutMs) {}
44
45size_t AudioQualityTest::GetNumVideoStreams() const {
kjellander8f8d1a02017-03-06 04:01:16 -080046 return 0;
47}
oprypin92220ff2017-03-23 03:40:03 -070048size_t AudioQualityTest::GetNumAudioStreams() const {
49 return 1;
50}
51size_t AudioQualityTest::GetNumFlexfecStreams() const {
52 return 0;
53}
54
55std::string AudioQualityTest::AudioInputFile() {
oprypinf2501002017-04-12 05:00:56 -070056 return test::ResourcePath("voice_engine/audio_tiny" + FileSampleRateSuffix(),
57 "wav");
oprypin92220ff2017-03-23 03:40:03 -070058}
59
60std::string AudioQualityTest::AudioOutputFile() {
61 const ::testing::TestInfo* const test_info =
62 ::testing::UnitTest::GetInstance()->current_test_info();
oprypinf2501002017-04-12 05:00:56 -070063 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
64 "_" + FileSampleRateSuffix() + ".wav";
oprypin92220ff2017-03-23 03:40:03 -070065}
66
67std::unique_ptr<test::FakeAudioDevice::Capturer>
68 AudioQualityTest::CreateCapturer() {
69 return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile());
70}
71
72std::unique_ptr<test::FakeAudioDevice::Renderer>
73 AudioQualityTest::CreateRenderer() {
74 return test::FakeAudioDevice::CreateBoundedWavFileWriter(
oprypin9b2f20c2017-08-29 05:51:57 -070075 AudioOutputFile(), FLAG_sample_rate_hz);
oprypin92220ff2017-03-23 03:40:03 -070076}
77
78void AudioQualityTest::OnFakeAudioDevicesCreated(
79 test::FakeAudioDevice* send_audio_device,
80 test::FakeAudioDevice* recv_audio_device) {
81 send_audio_device_ = send_audio_device;
82}
83
84FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() {
85 return FakeNetworkPipe::Config();
86}
87
88test::PacketTransport* AudioQualityTest::CreateSendTransport(
eladalon413ee9a2017-08-22 04:02:52 -070089 SingleThreadedTaskQueueForTesting* task_queue,
oprypin92220ff2017-03-23 03:40:03 -070090 Call* sender_call) {
91 return new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -070092 task_queue, sender_call, this, test::PacketTransport::kSender,
minyue20c84cc2017-04-10 16:57:57 -070093 test::CallTest::payload_type_map_, GetNetworkPipeConfig());
oprypin92220ff2017-03-23 03:40:03 -070094}
95
eladalon413ee9a2017-08-22 04:02:52 -070096test::PacketTransport* AudioQualityTest::CreateReceiveTransport(
97 SingleThreadedTaskQueueForTesting* task_queue) {
minyue20c84cc2017-04-10 16:57:57 -070098 return new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -070099 task_queue, nullptr, this, test::PacketTransport::kReceiver,
minyue20c84cc2017-04-10 16:57:57 -0700100 test::CallTest::payload_type_map_, GetNetworkPipeConfig());
oprypin92220ff2017-03-23 03:40:03 -0700101}
102
103void AudioQualityTest::ModifyAudioConfigs(
104 AudioSendStream::Config* send_config,
105 std::vector<AudioReceiveStream::Config>* receive_configs) {
ossu20a4b3f2017-04-27 02:08:52 -0700106 // 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});
oprypin92220ff2017-03-23 03:40:03 -0700112}
113
114void AudioQualityTest::PerformTest() {
oprypin9b2f20c2017-08-29 05:51:57 -0700115 if (FLAG_quick) {
oprypin76a1ce72017-05-04 03:06:18 -0700116 // 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 }
oprypin92220ff2017-03-23 03:40:03 -0700124}
125
126void 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.
oprypin6d305ba2017-03-30 04:01:30 -0700132 printf("TEST %s %s %s\n", test_info->name(),
oprypin92220ff2017-03-23 03:40:03 -0700133 AudioInputFile().c_str(), AudioOutputFile().c_str());
134}
135
136
137using LowBandwidthAudioTest = CallTest;
138
139TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
140 AudioQualityTest test;
141 RunBaseTest(&test);
142}
143
144
145class Mobile2GNetworkTest : public AudioQualityTest {
146 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
147 std::vector<AudioReceiveStream::Config>* receive_configs) override {
ossu20a4b3f2017-04-27 02:08:52 -0700148 send_config->send_codec_spec =
149 rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
150 {test::CallTest::kAudioSendPayloadType,
151 {"OPUS",
152 48000,
153 2,
154 {{"maxaveragebitrate", "6000"},
155 {"ptime", "60"},
156 {"stereo", "1"}}}});
oprypin92220ff2017-03-23 03:40:03 -0700157 }
158
159 FakeNetworkPipe::Config GetNetworkPipeConfig() override {
160 FakeNetworkPipe::Config pipe_config;
161 pipe_config.link_capacity_kbps = 12;
162 pipe_config.queue_length_packets = 1500;
163 pipe_config.queue_delay_ms = 400;
164 return pipe_config;
165 }
166};
167
168TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
169 Mobile2GNetworkTest test;
170 RunBaseTest(&test);
171}
172
173} // namespace test
174} // namespace webrtc