blob: 169f4bf592c4419de49ac1989ca175b9d1a482f8 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "audio/test/audio_end_to_end_test.h"
12#include "rtc_base/flags.h"
13#include "system_wrappers/include/sleep.h"
14#include "test/testsupport/fileutils.h"
oprypin92220ff2017-03-23 03:40:03 -070015
Yves Gerey665174f2018-06-19 15:03:05 +020016DEFINE_int(sample_rate_hz,
17 16000,
oprypin9b2f20c2017-08-29 05:51:57 -070018 "Sample rate (Hz) of the produced audio files.");
oprypinf2501002017-04-12 05:00:56 -070019
Yves Gerey665174f2018-06-19 15:03:05 +020020DEFINE_bool(quick,
21 false,
oprypin76a1ce72017-05-04 03:06:18 -070022 "Don't do the full audio recording. "
23 "Used to quickly check that the test runs without crashing.");
24
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020025namespace webrtc {
26namespace test {
oprypin92220ff2017-03-23 03:40:03 -070027namespace {
oprypinf2501002017-04-12 05:00:56 -070028
oprypinf2501002017-04-12 05:00:56 -070029std::string FileSampleRateSuffix() {
oprypin9b2f20c2017-08-29 05:51:57 -070030 return std::to_string(FLAG_sample_rate_hz / 1000);
oprypinf2501002017-04-12 05:00:56 -070031}
32
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020033class AudioQualityTest : public AudioEndToEndTest {
34 public:
35 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070036
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020037 private:
38 std::string AudioInputFile() const {
39 return test::ResourcePath(
40 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070041 }
oprypin92220ff2017-03-23 03:40:03 -070042
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020043 std::string AudioOutputFile() const {
44 const ::testing::TestInfo* const test_info =
45 ::testing::UnitTest::GetInstance()->current_test_info();
46 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
Yves Gerey665174f2018-06-19 15:03:05 +020047 "_" + FileSampleRateSuffix() + ".wav";
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020048 }
oprypin92220ff2017-03-23 03:40:03 -070049
Artem Titov3faa8322018-03-07 14:44:00 +010050 std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
51 return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020052 }
oprypin92220ff2017-03-23 03:40:03 -070053
Artem Titov3faa8322018-03-07 14:44:00 +010054 std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
55 return TestAudioDeviceModule::CreateBoundedWavFileWriter(
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020056 AudioOutputFile(), FLAG_sample_rate_hz);
57 }
oprypin92220ff2017-03-23 03:40:03 -070058
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020059 void PerformTest() override {
60 if (FLAG_quick) {
61 // Let the recording run for a small amount of time to check if it works.
62 SleepMs(1000);
63 } else {
64 AudioEndToEndTest::PerformTest();
65 }
66 }
oprypin92220ff2017-03-23 03:40:03 -070067
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020068 void OnStreamsStopped() override {
69 const ::testing::TestInfo* const test_info =
70 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070071
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020072 // Output information about the input and output audio files so that further
73 // processing can be done by an external process.
Yves Gerey665174f2018-06-19 15:03:05 +020074 printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
75 AudioOutputFile().c_str());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020076 }
77};
oprypin92220ff2017-03-23 03:40:03 -070078
79class Mobile2GNetworkTest : public AudioQualityTest {
Yves Gerey665174f2018-06-19 15:03:05 +020080 void ModifyAudioConfigs(
81 AudioSendStream::Config* send_config,
oprypin92220ff2017-03-23 03:40:03 -070082 std::vector<AudioReceiveStream::Config>* receive_configs) override {
Oskar Sundbom2707fb22017-11-16 10:57:35 +010083 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
84 test::CallTest::kAudioSendPayloadType,
85 {"OPUS",
86 48000,
87 2,
Yves Gerey665174f2018-06-19 15:03:05 +020088 {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
oprypin92220ff2017-03-23 03:40:03 -070089 }
90
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020091 FakeNetworkPipe::Config GetNetworkPipeConfig() const override {
oprypin92220ff2017-03-23 03:40:03 -070092 FakeNetworkPipe::Config pipe_config;
93 pipe_config.link_capacity_kbps = 12;
94 pipe_config.queue_length_packets = 1500;
95 pipe_config.queue_delay_ms = 400;
96 return pipe_config;
97 }
98};
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020099} // namespace
100
101using LowBandwidthAudioTest = CallTest;
102
103TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
104 AudioQualityTest test;
105 RunBaseTest(&test);
106}
oprypin92220ff2017-03-23 03:40:03 -0700107
108TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
109 Mobile2GNetworkTest test;
110 RunBaseTest(&test);
111}
oprypin92220ff2017-03-23 03:40:03 -0700112} // namespace test
113} // namespace webrtc