kjellander | 8f8d1a0 | 2017-03-06 04:01:16 -0800 | [diff] [blame] | 1 | /* |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
kjellander | 8f8d1a0 | 2017-03-06 04:01:16 -0800 | [diff] [blame] | 3 | * |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #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" |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 15 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 16 | DEFINE_int(sample_rate_hz, |
| 17 | 16000, |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 18 | "Sample rate (Hz) of the produced audio files."); |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 19 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 20 | DEFINE_bool(quick, |
| 21 | false, |
oprypin | 76a1ce7 | 2017-05-04 03:06:18 -0700 | [diff] [blame] | 22 | "Don't do the full audio recording. " |
| 23 | "Used to quickly check that the test runs without crashing."); |
| 24 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 25 | namespace webrtc { |
| 26 | namespace test { |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 27 | namespace { |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 28 | |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 29 | std::string FileSampleRateSuffix() { |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 30 | return std::to_string(FLAG_sample_rate_hz / 1000); |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 33 | class AudioQualityTest : public AudioEndToEndTest { |
| 34 | public: |
| 35 | AudioQualityTest() = default; |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 36 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 37 | private: |
| 38 | std::string AudioInputFile() const { |
| 39 | return test::ResourcePath( |
| 40 | "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav"); |
oprypin | 76a1ce7 | 2017-05-04 03:06:18 -0700 | [diff] [blame] | 41 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 42 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 43 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 47 | "_" + FileSampleRateSuffix() + ".wav"; |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 48 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 49 | |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 50 | std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override { |
| 51 | return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile()); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 52 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 53 | |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 54 | std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override { |
| 55 | return TestAudioDeviceModule::CreateBoundedWavFileWriter( |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 56 | AudioOutputFile(), FLAG_sample_rate_hz); |
| 57 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 58 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 59 | 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 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 67 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 68 | void OnStreamsStopped() override { |
| 69 | const ::testing::TestInfo* const test_info = |
| 70 | ::testing::UnitTest::GetInstance()->current_test_info(); |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 71 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 72 | // Output information about the input and output audio files so that further |
| 73 | // processing can be done by an external process. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 74 | printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(), |
| 75 | AudioOutputFile().c_str()); |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 76 | } |
| 77 | }; |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 78 | |
| 79 | class Mobile2GNetworkTest : public AudioQualityTest { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 80 | void ModifyAudioConfigs( |
| 81 | AudioSendStream::Config* send_config, |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 82 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
Oskar Sundbom | 2707fb2 | 2017-11-16 10:57:35 +0100 | [diff] [blame] | 83 | send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
| 84 | test::CallTest::kAudioSendPayloadType, |
| 85 | {"OPUS", |
| 86 | 48000, |
| 87 | 2, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 88 | {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}}); |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 91 | FakeNetworkPipe::Config GetNetworkPipeConfig() const override { |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 92 | 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 Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 99 | } // namespace |
| 100 | |
| 101 | using LowBandwidthAudioTest = CallTest; |
| 102 | |
| 103 | TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) { |
| 104 | AudioQualityTest test; |
| 105 | RunBaseTest(&test); |
| 106 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 107 | |
| 108 | TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { |
| 109 | Mobile2GNetworkTest test; |
| 110 | RunBaseTest(&test); |
| 111 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 112 | } // namespace test |
| 113 | } // namespace webrtc |