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 | |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 11 | #include <algorithm> |
kjellander | 8f8d1a0 | 2017-03-06 04:01:16 -0800 | [diff] [blame] | 12 | |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 13 | #include "webrtc/audio/test/low_bandwidth_audio_test.h" |
| 14 | #include "webrtc/common_audio/wav_file.h" |
| 15 | #include "webrtc/test/gtest.h" |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/sleep.h" |
| 17 | #include "webrtc/test/testsupport/fileutils.h" |
| 18 | |
| 19 | namespace { |
| 20 | // Wait half a second between stopping sending and stopping receiving audio. |
| 21 | constexpr int kExtraRecordTimeMs = 500; |
| 22 | |
| 23 | // Large bitrate by default. |
| 24 | const webrtc::CodecInst kDefaultCodec{120, "OPUS", 48000, 960, 2, 64000}; |
| 25 | |
| 26 | // The best that can be done with PESQ. |
| 27 | constexpr int kAudioFileBitRate = 16000; |
| 28 | } |
| 29 | |
| 30 | namespace webrtc { |
| 31 | namespace test { |
| 32 | |
| 33 | AudioQualityTest::AudioQualityTest() |
| 34 | : EndToEndTest(CallTest::kDefaultTimeoutMs) {} |
| 35 | |
| 36 | size_t AudioQualityTest::GetNumVideoStreams() const { |
kjellander | 8f8d1a0 | 2017-03-06 04:01:16 -0800 | [diff] [blame] | 37 | return 0; |
| 38 | } |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 39 | size_t AudioQualityTest::GetNumAudioStreams() const { |
| 40 | return 1; |
| 41 | } |
| 42 | size_t AudioQualityTest::GetNumFlexfecStreams() const { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | std::string AudioQualityTest::AudioInputFile() { |
| 47 | return test::ResourcePath("voice_engine/audio_tiny16", "wav"); |
| 48 | } |
| 49 | |
| 50 | std::string AudioQualityTest::AudioOutputFile() { |
| 51 | const ::testing::TestInfo* const test_info = |
| 52 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 53 | return webrtc::test::OutputPath() + |
| 54 | "LowBandwidth_" + test_info->name() + ".wav"; |
| 55 | } |
| 56 | |
| 57 | std::unique_ptr<test::FakeAudioDevice::Capturer> |
| 58 | AudioQualityTest::CreateCapturer() { |
| 59 | return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile()); |
| 60 | } |
| 61 | |
| 62 | std::unique_ptr<test::FakeAudioDevice::Renderer> |
| 63 | AudioQualityTest::CreateRenderer() { |
| 64 | return test::FakeAudioDevice::CreateBoundedWavFileWriter( |
| 65 | AudioOutputFile(), kAudioFileBitRate); |
| 66 | } |
| 67 | |
| 68 | void AudioQualityTest::OnFakeAudioDevicesCreated( |
| 69 | test::FakeAudioDevice* send_audio_device, |
| 70 | test::FakeAudioDevice* recv_audio_device) { |
| 71 | send_audio_device_ = send_audio_device; |
| 72 | } |
| 73 | |
| 74 | FakeNetworkPipe::Config AudioQualityTest::GetNetworkPipeConfig() { |
| 75 | return FakeNetworkPipe::Config(); |
| 76 | } |
| 77 | |
| 78 | test::PacketTransport* AudioQualityTest::CreateSendTransport( |
| 79 | Call* sender_call) { |
| 80 | return new test::PacketTransport( |
| 81 | sender_call, this, test::PacketTransport::kSender, |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 82 | MediaType::AUDIO, |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 83 | GetNetworkPipeConfig()); |
| 84 | } |
| 85 | |
| 86 | test::PacketTransport* AudioQualityTest::CreateReceiveTransport() { |
| 87 | return new test::PacketTransport(nullptr, this, |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 88 | test::PacketTransport::kReceiver, MediaType::AUDIO, |
| 89 | GetNetworkPipeConfig()); |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void AudioQualityTest::ModifyAudioConfigs( |
| 93 | AudioSendStream::Config* send_config, |
| 94 | std::vector<AudioReceiveStream::Config>* receive_configs) { |
| 95 | send_config->send_codec_spec.codec_inst = kDefaultCodec; |
| 96 | } |
| 97 | |
| 98 | void AudioQualityTest::PerformTest() { |
| 99 | // Wait until the input audio file is done... |
| 100 | send_audio_device_->WaitForRecordingEnd(); |
| 101 | // and some extra time to account for network delay. |
| 102 | SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs); |
| 103 | } |
| 104 | |
| 105 | void AudioQualityTest::OnTestFinished() { |
| 106 | const ::testing::TestInfo* const test_info = |
| 107 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 108 | |
| 109 | // Output information about the input and output audio files so that further |
| 110 | // processing can be done by an external process. |
oprypin | 6d305ba | 2017-03-30 04:01:30 -0700 | [diff] [blame^] | 111 | printf("TEST %s %s %s\n", test_info->name(), |
oprypin | 92220ff | 2017-03-23 03:40:03 -0700 | [diff] [blame] | 112 | AudioInputFile().c_str(), AudioOutputFile().c_str()); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | using LowBandwidthAudioTest = CallTest; |
| 117 | |
| 118 | TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) { |
| 119 | AudioQualityTest test; |
| 120 | RunBaseTest(&test); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | class Mobile2GNetworkTest : public AudioQualityTest { |
| 125 | void ModifyAudioConfigs(AudioSendStream::Config* send_config, |
| 126 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 127 | send_config->send_codec_spec.codec_inst = CodecInst{ |
| 128 | 120, // pltype |
| 129 | "OPUS", // plname |
| 130 | 48000, // plfreq |
| 131 | 2880, // pacsize |
| 132 | 1, // channels |
| 133 | 6000 // rate bits/sec |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | FakeNetworkPipe::Config GetNetworkPipeConfig() override { |
| 138 | FakeNetworkPipe::Config pipe_config; |
| 139 | pipe_config.link_capacity_kbps = 12; |
| 140 | pipe_config.queue_length_packets = 1500; |
| 141 | pipe_config.queue_delay_ms = 400; |
| 142 | return pipe_config; |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) { |
| 147 | Mobile2GNetworkTest test; |
| 148 | RunBaseTest(&test); |
| 149 | } |
| 150 | |
| 151 | } // namespace test |
| 152 | } // namespace webrtc |