blob: 049b5e51505e61586eeb2340a94b256098de72ca [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 Bonadei2ab97f62019-07-18 13:44:12 +020011#include "absl/flags/flag.h"
Artem Titov46c4e602018-08-17 14:26:54 +020012#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "audio/test/audio_end_to_end_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#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 Bonadei2ab97f62019-07-18 13:44:12 +020017ABSL_DECLARE_FLAG(int, sample_rate_hz);
18ABSL_DECLARE_FLAG(bool, quick);
oprypin76a1ce72017-05-04 03:06:18 -070019
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020020namespace webrtc {
21namespace test {
oprypin92220ff2017-03-23 03:40:03 -070022namespace {
oprypinf2501002017-04-12 05:00:56 -070023
oprypinf2501002017-04-12 05:00:56 -070024std::string FileSampleRateSuffix() {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020025 return std::to_string(absl::GetFlag(FLAGS_sample_rate_hz) / 1000);
oprypinf2501002017-04-12 05:00:56 -070026}
27
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020028class AudioQualityTest : public AudioEndToEndTest {
29 public:
30 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070031
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020032 private:
33 std::string AudioInputFile() const {
34 return test::ResourcePath(
35 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070036 }
oprypin92220ff2017-03-23 03:40:03 -070037
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020038 std::string AudioOutputFile() const {
39 const ::testing::TestInfo* const test_info =
40 ::testing::UnitTest::GetInstance()->current_test_info();
41 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
Yves Gerey665174f2018-06-19 15:03:05 +020042 "_" + FileSampleRateSuffix() + ".wav";
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020043 }
oprypin92220ff2017-03-23 03:40:03 -070044
Artem Titov3faa8322018-03-07 14:44:00 +010045 std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
46 return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020047 }
oprypin92220ff2017-03-23 03:40:03 -070048
Artem Titov3faa8322018-03-07 14:44:00 +010049 std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
50 return TestAudioDeviceModule::CreateBoundedWavFileWriter(
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020051 AudioOutputFile(), absl::GetFlag(FLAGS_sample_rate_hz));
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020052 }
oprypin92220ff2017-03-23 03:40:03 -070053
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020054 void PerformTest() override {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020055 if (absl::GetFlag(FLAGS_quick)) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020056 // Let the recording run for a small amount of time to check if it works.
57 SleepMs(1000);
58 } else {
59 AudioEndToEndTest::PerformTest();
60 }
61 }
oprypin92220ff2017-03-23 03:40:03 -070062
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020063 void OnStreamsStopped() override {
64 const ::testing::TestInfo* const test_info =
65 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070066
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020067 // Output information about the input and output audio files so that further
68 // processing can be done by an external process.
Yves Gerey665174f2018-06-19 15:03:05 +020069 printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
70 AudioOutputFile().c_str());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020071 }
72};
oprypin92220ff2017-03-23 03:40:03 -070073
74class Mobile2GNetworkTest : public AudioQualityTest {
Yves Gerey665174f2018-06-19 15:03:05 +020075 void ModifyAudioConfigs(
76 AudioSendStream::Config* send_config,
oprypin92220ff2017-03-23 03:40:03 -070077 std::vector<AudioReceiveStream::Config>* receive_configs) override {
Oskar Sundbom2707fb22017-11-16 10:57:35 +010078 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
79 test::CallTest::kAudioSendPayloadType,
80 {"OPUS",
81 48000,
82 2,
Yves Gerey665174f2018-06-19 15:03:05 +020083 {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
oprypin92220ff2017-03-23 03:40:03 -070084 }
85
Artem Titov75e36472018-10-08 12:28:56 +020086 BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
87 BuiltInNetworkBehaviorConfig pipe_config;
oprypin92220ff2017-03-23 03:40:03 -070088 pipe_config.link_capacity_kbps = 12;
89 pipe_config.queue_length_packets = 1500;
90 pipe_config.queue_delay_ms = 400;
91 return pipe_config;
92 }
93};
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020094} // namespace
95
96using LowBandwidthAudioTest = CallTest;
97
98TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
99 AudioQualityTest test;
100 RunBaseTest(&test);
101}
oprypin92220ff2017-03-23 03:40:03 -0700102
103TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
104 Mobile2GNetworkTest test;
105 RunBaseTest(&test);
106}
oprypin92220ff2017-03-23 03:40:03 -0700107} // namespace test
108} // namespace webrtc