blob: 50cf4999202df371bb4349cacca2b3dc91b1ed49 [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 Titov506d4eb2020-06-05 17:04:26 +020011#include "absl/flags/declare.h"
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020012#include "absl/flags/flag.h"
Artem Titov46c4e602018-08-17 14:26:54 +020013#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "audio/test/audio_end_to_end_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "system_wrappers/include/sleep.h"
Steve Anton10542f22019-01-11 09:11:00 -080016#include "test/testsupport/file_utils.h"
oprypin92220ff2017-03-23 03:40:03 -070017
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020018ABSL_DECLARE_FLAG(int, sample_rate_hz);
19ABSL_DECLARE_FLAG(bool, quick);
oprypin76a1ce72017-05-04 03:06:18 -070020
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020021namespace webrtc {
22namespace test {
oprypin92220ff2017-03-23 03:40:03 -070023namespace {
oprypinf2501002017-04-12 05:00:56 -070024
oprypinf2501002017-04-12 05:00:56 -070025std::string FileSampleRateSuffix() {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020026 return std::to_string(absl::GetFlag(FLAGS_sample_rate_hz) / 1000);
oprypinf2501002017-04-12 05:00:56 -070027}
28
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020029class AudioQualityTest : public AudioEndToEndTest {
30 public:
31 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070032
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020033 private:
34 std::string AudioInputFile() const {
35 return test::ResourcePath(
36 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070037 }
oprypin92220ff2017-03-23 03:40:03 -070038
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020039 std::string AudioOutputFile() const {
40 const ::testing::TestInfo* const test_info =
41 ::testing::UnitTest::GetInstance()->current_test_info();
42 return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() +
Yves Gerey665174f2018-06-19 15:03:05 +020043 "_" + FileSampleRateSuffix() + ".wav";
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020044 }
oprypin92220ff2017-03-23 03:40:03 -070045
Artem Titov3faa8322018-03-07 14:44:00 +010046 std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
47 return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
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::Renderer> CreateRenderer() override {
51 return TestAudioDeviceModule::CreateBoundedWavFileWriter(
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020052 AudioOutputFile(), absl::GetFlag(FLAGS_sample_rate_hz));
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020053 }
oprypin92220ff2017-03-23 03:40:03 -070054
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020055 void PerformTest() override {
Mirko Bonadei2ab97f62019-07-18 13:44:12 +020056 if (absl::GetFlag(FLAGS_quick)) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020057 // Let the recording run for a small amount of time to check if it works.
58 SleepMs(1000);
59 } else {
60 AudioEndToEndTest::PerformTest();
61 }
62 }
oprypin92220ff2017-03-23 03:40:03 -070063
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020064 void OnStreamsStopped() override {
65 const ::testing::TestInfo* const test_info =
66 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070067
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020068 // Output information about the input and output audio files so that further
69 // processing can be done by an external process.
Yves Gerey665174f2018-06-19 15:03:05 +020070 printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
71 AudioOutputFile().c_str());
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020072 }
73};
oprypin92220ff2017-03-23 03:40:03 -070074
75class Mobile2GNetworkTest : public AudioQualityTest {
Yves Gerey665174f2018-06-19 15:03:05 +020076 void ModifyAudioConfigs(
77 AudioSendStream::Config* send_config,
oprypin92220ff2017-03-23 03:40:03 -070078 std::vector<AudioReceiveStream::Config>* receive_configs) override {
Oskar Sundbom2707fb22017-11-16 10:57:35 +010079 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
80 test::CallTest::kAudioSendPayloadType,
81 {"OPUS",
82 48000,
83 2,
Yves Gerey665174f2018-06-19 15:03:05 +020084 {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
oprypin92220ff2017-03-23 03:40:03 -070085 }
86
Artem Titov75e36472018-10-08 12:28:56 +020087 BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
88 BuiltInNetworkBehaviorConfig pipe_config;
oprypin92220ff2017-03-23 03:40:03 -070089 pipe_config.link_capacity_kbps = 12;
90 pipe_config.queue_length_packets = 1500;
91 pipe_config.queue_delay_ms = 400;
92 return pipe_config;
93 }
94};
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020095} // namespace
96
97using LowBandwidthAudioTest = CallTest;
98
99TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
100 AudioQualityTest test;
101 RunBaseTest(&test);
102}
oprypin92220ff2017-03-23 03:40:03 -0700103
104TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
105 Mobile2GNetworkTest test;
106 RunBaseTest(&test);
107}
oprypin92220ff2017-03-23 03:40:03 -0700108} // namespace test
109} // namespace webrtc