blob: 16a3b91e877cdd88d6f93f8ed6f22b9bc92ab437 [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
Artem Titov46c4e602018-08-17 14:26:54 +020011#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020012#include "audio/test/audio_end_to_end_test.h"
13#include "rtc_base/flags.h"
14#include "system_wrappers/include/sleep.h"
15#include "test/testsupport/fileutils.h"
oprypin92220ff2017-03-23 03:40:03 -070016
Yves Gerey665174f2018-06-19 15:03:05 +020017DEFINE_int(sample_rate_hz,
18 16000,
oprypin9b2f20c2017-08-29 05:51:57 -070019 "Sample rate (Hz) of the produced audio files.");
oprypinf2501002017-04-12 05:00:56 -070020
Yves Gerey665174f2018-06-19 15:03:05 +020021DEFINE_bool(quick,
22 false,
oprypin76a1ce72017-05-04 03:06:18 -070023 "Don't do the full audio recording. "
24 "Used to quickly check that the test runs without crashing.");
25
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020026namespace webrtc {
27namespace test {
oprypin92220ff2017-03-23 03:40:03 -070028namespace {
oprypinf2501002017-04-12 05:00:56 -070029
oprypinf2501002017-04-12 05:00:56 -070030std::string FileSampleRateSuffix() {
oprypin9b2f20c2017-08-29 05:51:57 -070031 return std::to_string(FLAG_sample_rate_hz / 1000);
oprypinf2501002017-04-12 05:00:56 -070032}
33
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020034class AudioQualityTest : public AudioEndToEndTest {
35 public:
36 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070037
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020038 private:
39 std::string AudioInputFile() const {
40 return test::ResourcePath(
41 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070042 }
oprypin92220ff2017-03-23 03:40:03 -070043
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020044 std::string AudioOutputFile() const {
45 const ::testing::TestInfo* const test_info =
46 ::testing::UnitTest::GetInstance()->current_test_info();
47 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
Yves Gerey665174f2018-06-19 15:03:05 +020048 "_" + FileSampleRateSuffix() + ".wav";
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020049 }
oprypin92220ff2017-03-23 03:40:03 -070050
Artem Titov3faa8322018-03-07 14:44:00 +010051 std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
52 return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020053 }
oprypin92220ff2017-03-23 03:40:03 -070054
Artem Titov3faa8322018-03-07 14:44:00 +010055 std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
56 return TestAudioDeviceModule::CreateBoundedWavFileWriter(
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020057 AudioOutputFile(), FLAG_sample_rate_hz);
58 }
oprypin92220ff2017-03-23 03:40:03 -070059
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020060 void PerformTest() override {
61 if (FLAG_quick) {
62 // Let the recording run for a small amount of time to check if it works.
63 SleepMs(1000);
64 } else {
65 AudioEndToEndTest::PerformTest();
66 }
67 }
oprypin92220ff2017-03-23 03:40:03 -070068
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020069 void OnStreamsStopped() override {
70 const ::testing::TestInfo* const test_info =
71 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070072
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020073 // Output information about the input and output audio files so that further
74 // processing can be done by an external process.
Yves Gerey665174f2018-06-19 15:03:05 +020075 printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
76 AudioOutputFile().c_str());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020077 }
78};
oprypin92220ff2017-03-23 03:40:03 -070079
80class Mobile2GNetworkTest : public AudioQualityTest {
Yves Gerey665174f2018-06-19 15:03:05 +020081 void ModifyAudioConfigs(
82 AudioSendStream::Config* send_config,
oprypin92220ff2017-03-23 03:40:03 -070083 std::vector<AudioReceiveStream::Config>* receive_configs) override {
Oskar Sundbom2707fb22017-11-16 10:57:35 +010084 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
85 test::CallTest::kAudioSendPayloadType,
86 {"OPUS",
87 48000,
88 2,
Yves Gerey665174f2018-06-19 15:03:05 +020089 {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
oprypin92220ff2017-03-23 03:40:03 -070090 }
91
Artem Titov46c4e602018-08-17 14:26:54 +020092 DefaultNetworkSimulationConfig GetNetworkPipeConfig() const override {
93 DefaultNetworkSimulationConfig pipe_config;
oprypin92220ff2017-03-23 03:40:03 -070094 pipe_config.link_capacity_kbps = 12;
95 pipe_config.queue_length_packets = 1500;
96 pipe_config.queue_delay_ms = 400;
97 return pipe_config;
98 }
99};
Fredrik Solenberg73276ad2017-09-14 14:46:47 +0200100} // namespace
101
102using LowBandwidthAudioTest = CallTest;
103
104TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
105 AudioQualityTest test;
106 RunBaseTest(&test);
107}
oprypin92220ff2017-03-23 03:40:03 -0700108
109TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
110 Mobile2GNetworkTest test;
111 RunBaseTest(&test);
112}
oprypin92220ff2017-03-23 03:40:03 -0700113} // namespace test
114} // namespace webrtc