blob: de955f75e19c936b98e61692f832d62254d8ffcc [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"
15#include "webrtc/test/gtest.h"
oprypin92220ff2017-03-23 03:40:03 -070016#include "webrtc/system_wrappers/include/sleep.h"
17#include "webrtc/test/testsupport/fileutils.h"
18
19namespace {
20// Wait half a second between stopping sending and stopping receiving audio.
21constexpr int kExtraRecordTimeMs = 500;
22
23// Large bitrate by default.
24const webrtc::CodecInst kDefaultCodec{120, "OPUS", 48000, 960, 2, 64000};
25
26// The best that can be done with PESQ.
27constexpr int kAudioFileBitRate = 16000;
28}
29
30namespace webrtc {
31namespace test {
32
33AudioQualityTest::AudioQualityTest()
34 : EndToEndTest(CallTest::kDefaultTimeoutMs) {}
35
36size_t AudioQualityTest::GetNumVideoStreams() const {
kjellander8f8d1a02017-03-06 04:01:16 -080037 return 0;
38}
oprypin92220ff2017-03-23 03:40:03 -070039size_t AudioQualityTest::GetNumAudioStreams() const {
40 return 1;
41}
42size_t AudioQualityTest::GetNumFlexfecStreams() const {
43 return 0;
44}
45
46std::string AudioQualityTest::AudioInputFile() {
47 return test::ResourcePath("voice_engine/audio_tiny16", "wav");
48}
49
50std::string AudioQualityTest::AudioOutputFile() {
51 const ::testing::TestInfo* const test_info =
52 ::testing::UnitTest::GetInstance()->current_test_info();
53 return webrtc::test::OutputPath() +
54 "LowBandwidth_" + test_info->name() + ".wav";
55}
56
57std::unique_ptr<test::FakeAudioDevice::Capturer>
58 AudioQualityTest::CreateCapturer() {
59 return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile());
60}
61
62std::unique_ptr<test::FakeAudioDevice::Renderer>
63 AudioQualityTest::CreateRenderer() {
64 return test::FakeAudioDevice::CreateBoundedWavFileWriter(
65 AudioOutputFile(), kAudioFileBitRate);
66}
67
68void AudioQualityTest::OnFakeAudioDevicesCreated(
69 test::FakeAudioDevice* send_audio_device,
70 test::FakeAudioDevice* recv_audio_device) {
71 send_audio_device_ = send_audio_device;
72}
73
74FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() {
75 return FakeNetworkPipe::Config();
76}
77
78test::PacketTransport* AudioQualityTest::CreateSendTransport(
79 Call* sender_call) {
80 return new test::PacketTransport(
81 sender_call, this, test::PacketTransport::kSender,
nissee5ad5ca2017-03-29 23:57:43 -070082 MediaType::AUDIO,
oprypin92220ff2017-03-23 03:40:03 -070083 GetNetworkPipeConfig());
84}
85
86test::PacketTransport* AudioQualityTest::CreateReceiveTransport() {
87 return new test::PacketTransport(nullptr, this,
nissee5ad5ca2017-03-29 23:57:43 -070088 test::PacketTransport::kReceiver, MediaType::AUDIO,
89 GetNetworkPipeConfig());
oprypin92220ff2017-03-23 03:40:03 -070090}
91
92void AudioQualityTest::ModifyAudioConfigs(
93 AudioSendStream::Config* send_config,
94 std::vector<AudioReceiveStream::Config>* receive_configs) {
95 send_config->send_codec_spec.codec_inst = kDefaultCodec;
96}
97
98void AudioQualityTest::PerformTest() {
99 // Wait until the input audio file is done...
100 send_audio_device_->WaitForRecordingEnd();
101 // and some extra time to account for network delay.
102 SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs);
103}
104
105void AudioQualityTest::OnTestFinished() {
106 const ::testing::TestInfo* const test_info =
107 ::testing::UnitTest::GetInstance()->current_test_info();
108
109 // Output information about the input and output audio files so that further
110 // processing can be done by an external process.
oprypin6d305ba2017-03-30 04:01:30 -0700111 printf("TEST %s %s %s\n", test_info->name(),
oprypin92220ff2017-03-23 03:40:03 -0700112 AudioInputFile().c_str(), AudioOutputFile().c_str());
113}
114
115
116using LowBandwidthAudioTest = CallTest;
117
118TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
119 AudioQualityTest test;
120 RunBaseTest(&test);
121}
122
123
124class Mobile2GNetworkTest : public AudioQualityTest {
125 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
126 std::vector<AudioReceiveStream::Config>* receive_configs) override {
127 send_config->send_codec_spec.codec_inst = CodecInst{
128 120, // pltype
129 "OPUS", // plname
130 48000, // plfreq
131 2880, // pacsize
132 1, // channels
133 6000 // rate bits/sec
134 };
135 }
136
137 FakeNetworkPipe::Config GetNetworkPipeConfig() override {
138 FakeNetworkPipe::Config pipe_config;
139 pipe_config.link_capacity_kbps = 12;
140 pipe_config.queue_length_packets = 1500;
141 pipe_config.queue_delay_ms = 400;
142 return pipe_config;
143 }
144};
145
146TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
147 Mobile2GNetworkTest test;
148 RunBaseTest(&test);
149}
150
151} // namespace test
152} // namespace webrtc