blob: 54191e85a6136cf24ddb84ea1154da03efa47da2 [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"
Steve Anton10542f22019-01-11 09:11:00 -080015#include "test/testsupport/file_utils.h"
oprypin92220ff2017-03-23 03:40:03 -070016
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020017WEBRTC_DEFINE_int(sample_rate_hz,
18 16000,
19 "Sample rate (Hz) of the produced audio files.");
oprypinf2501002017-04-12 05:00:56 -070020
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020021WEBRTC_DEFINE_bool(
22 quick,
23 false,
24 "Don't do the full audio recording. "
25 "Used to quickly check that the test runs without crashing.");
oprypin76a1ce72017-05-04 03:06:18 -070026
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020027namespace webrtc {
28namespace test {
oprypin92220ff2017-03-23 03:40:03 -070029namespace {
oprypinf2501002017-04-12 05:00:56 -070030
oprypinf2501002017-04-12 05:00:56 -070031std::string FileSampleRateSuffix() {
oprypin9b2f20c2017-08-29 05:51:57 -070032 return std::to_string(FLAG_sample_rate_hz / 1000);
oprypinf2501002017-04-12 05:00:56 -070033}
34
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020035class AudioQualityTest : public AudioEndToEndTest {
36 public:
37 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070038
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020039 private:
40 std::string AudioInputFile() const {
41 return test::ResourcePath(
42 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070043 }
oprypin92220ff2017-03-23 03:40:03 -070044
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020045 std::string AudioOutputFile() const {
46 const ::testing::TestInfo* const test_info =
47 ::testing::UnitTest::GetInstance()->current_test_info();
48 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
Yves Gerey665174f2018-06-19 15:03:05 +020049 "_" + FileSampleRateSuffix() + ".wav";
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020050 }
oprypin92220ff2017-03-23 03:40:03 -070051
Artem Titov3faa8322018-03-07 14:44:00 +010052 std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
53 return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020054 }
oprypin92220ff2017-03-23 03:40:03 -070055
Artem Titov3faa8322018-03-07 14:44:00 +010056 std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
57 return TestAudioDeviceModule::CreateBoundedWavFileWriter(
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020058 AudioOutputFile(), FLAG_sample_rate_hz);
59 }
oprypin92220ff2017-03-23 03:40:03 -070060
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020061 void PerformTest() override {
62 if (FLAG_quick) {
63 // Let the recording run for a small amount of time to check if it works.
64 SleepMs(1000);
65 } else {
66 AudioEndToEndTest::PerformTest();
67 }
68 }
oprypin92220ff2017-03-23 03:40:03 -070069
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020070 void OnStreamsStopped() override {
71 const ::testing::TestInfo* const test_info =
72 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070073
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020074 // Output information about the input and output audio files so that further
75 // processing can be done by an external process.
Yves Gerey665174f2018-06-19 15:03:05 +020076 printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
77 AudioOutputFile().c_str());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020078 }
79};
oprypin92220ff2017-03-23 03:40:03 -070080
81class Mobile2GNetworkTest : public AudioQualityTest {
Yves Gerey665174f2018-06-19 15:03:05 +020082 void ModifyAudioConfigs(
83 AudioSendStream::Config* send_config,
oprypin92220ff2017-03-23 03:40:03 -070084 std::vector<AudioReceiveStream::Config>* receive_configs) override {
Oskar Sundbom2707fb22017-11-16 10:57:35 +010085 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
86 test::CallTest::kAudioSendPayloadType,
87 {"OPUS",
88 48000,
89 2,
Yves Gerey665174f2018-06-19 15:03:05 +020090 {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
oprypin92220ff2017-03-23 03:40:03 -070091 }
92
Artem Titov75e36472018-10-08 12:28:56 +020093 BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
94 BuiltInNetworkBehaviorConfig pipe_config;
oprypin92220ff2017-03-23 03:40:03 -070095 pipe_config.link_capacity_kbps = 12;
96 pipe_config.queue_length_packets = 1500;
97 pipe_config.queue_delay_ms = 400;
98 return pipe_config;
99 }
100};
Fredrik Solenberg73276ad2017-09-14 14:46:47 +0200101} // namespace
102
103using LowBandwidthAudioTest = CallTest;
104
105TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
106 AudioQualityTest test;
107 RunBaseTest(&test);
108}
oprypin92220ff2017-03-23 03:40:03 -0700109
110TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
111 Mobile2GNetworkTest test;
112 RunBaseTest(&test);
113}
oprypin92220ff2017-03-23 03:40:03 -0700114} // namespace test
115} // namespace webrtc