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 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 16 | DEFINE_int(sample_rate_hz, 16000, |
| 17 | "Sample rate (Hz) of the produced audio files."); |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 18 | |
oprypin | 76a1ce7 | 2017-05-04 03:06:18 -0700 | [diff] [blame] | 19 | DEFINE_bool(quick, false, |
| 20 | "Don't do the full audio recording. " |
| 21 | "Used to quickly check that the test runs without crashing."); |
| 22 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 23 | namespace webrtc { |
| 24 | namespace test { |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 25 | namespace { |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 26 | |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 27 | std::string FileSampleRateSuffix() { |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 28 | return std::to_string(FLAG_sample_rate_hz / 1000); |
oprypin | f250100 | 2017-04-12 05:00:56 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 31 | class AudioQualityTest : public AudioEndToEndTest { |
| 32 | public: |
| 33 | AudioQualityTest() = default; |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 34 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 35 | private: |
| 36 | std::string AudioInputFile() const { |
| 37 | return test::ResourcePath( |
| 38 | "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav"); |
oprypin | 76a1ce7 | 2017-05-04 03:06:18 -0700 | [diff] [blame] | 39 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 40 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 41 | std::string AudioOutputFile() const { |
| 42 | const ::testing::TestInfo* const test_info = |
| 43 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 44 | return webrtc::test::OutputPath() + "LowBandwidth_" + test_info->name() + |
| 45 | "_" + FileSampleRateSuffix() + ".wav"; |
| 46 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 47 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 48 | std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override { |
| 49 | return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile()); |
| 50 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 51 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 52 | std::unique_ptr<test::FakeAudioDevice::Renderer> CreateRenderer() override { |
| 53 | return test::FakeAudioDevice::CreateBoundedWavFileWriter( |
| 54 | AudioOutputFile(), FLAG_sample_rate_hz); |
| 55 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 56 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 57 | void PerformTest() override { |
| 58 | if (FLAG_quick) { |
| 59 | // Let the recording run for a small amount of time to check if it works. |
| 60 | SleepMs(1000); |
| 61 | } else { |
| 62 | AudioEndToEndTest::PerformTest(); |
| 63 | } |
| 64 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 65 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 66 | void OnStreamsStopped() override { |
| 67 | const ::testing::TestInfo* const test_info = |
| 68 | ::testing::UnitTest::GetInstance()->current_test_info(); |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 69 | |
Fredrik Solenberg | 73276ad | 2017-09-14 14:46:47 +0200 | [diff] [blame] | 70 | // Output information about the input and output audio files so that further |
| 71 | // processing can be done by an external process. |
| 72 | printf("TEST %s %s %s\n", test_info->name(), |
| 73 | AudioInputFile().c_str(), AudioOutputFile().c_str()); |
| 74 | } |
| 75 | }; |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 76 | |
| 77 | class Mobile2GNetworkTest : public AudioQualityTest { |
| 78 | void ModifyAudioConfigs(AudioSendStream::Config* send_config, |
| 79 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 80 | send_config->send_codec_spec = |
| 81 | rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
| 82 | {test::CallTest::kAudioSendPayloadType, |
| 83 | {"OPUS", |
| 84 | 48000, |
| 85 | 2, |
| 86 | {{"maxaveragebitrate", "6000"}, |
| 87 | {"ptime", "60"}, |
| 88 | {"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 |