blob: b3c674da6162b13a8c8d55724abc02b4a6f26f9d [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 Bonadei92ea95e2017-09-15 06:47:31 +020011#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"
oprypin92220ff2017-03-23 03:40:03 -070015
oprypin9b2f20c2017-08-29 05:51:57 -070016DEFINE_int(sample_rate_hz, 16000,
17 "Sample rate (Hz) of the produced audio files.");
oprypinf2501002017-04-12 05:00:56 -070018
oprypin76a1ce72017-05-04 03:06:18 -070019DEFINE_bool(quick, false,
20 "Don't do the full audio recording. "
21 "Used to quickly check that the test runs without crashing.");
22
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020023namespace webrtc {
24namespace test {
oprypin92220ff2017-03-23 03:40:03 -070025namespace {
oprypinf2501002017-04-12 05:00:56 -070026
oprypinf2501002017-04-12 05:00:56 -070027std::string FileSampleRateSuffix() {
oprypin9b2f20c2017-08-29 05:51:57 -070028 return std::to_string(FLAG_sample_rate_hz / 1000);
oprypinf2501002017-04-12 05:00:56 -070029}
30
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020031class AudioQualityTest : public AudioEndToEndTest {
32 public:
33 AudioQualityTest() = default;
oprypin92220ff2017-03-23 03:40:03 -070034
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020035 private:
36 std::string AudioInputFile() const {
37 return test::ResourcePath(
38 "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
oprypin76a1ce72017-05-04 03:06:18 -070039 }
oprypin92220ff2017-03-23 03:40:03 -070040
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020041 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 }
oprypin92220ff2017-03-23 03:40:03 -070047
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020048 std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override {
49 return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile());
50 }
oprypin92220ff2017-03-23 03:40:03 -070051
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020052 std::unique_ptr<test::FakeAudioDevice::Renderer> CreateRenderer() override {
53 return test::FakeAudioDevice::CreateBoundedWavFileWriter(
54 AudioOutputFile(), FLAG_sample_rate_hz);
55 }
oprypin92220ff2017-03-23 03:40:03 -070056
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020057 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 }
oprypin92220ff2017-03-23 03:40:03 -070065
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020066 void OnStreamsStopped() override {
67 const ::testing::TestInfo* const test_info =
68 ::testing::UnitTest::GetInstance()->current_test_info();
oprypin92220ff2017-03-23 03:40:03 -070069
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020070 // 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};
oprypin92220ff2017-03-23 03:40:03 -070076
77class Mobile2GNetworkTest : public AudioQualityTest {
78 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
79 std::vector<AudioReceiveStream::Config>* receive_configs) override {
ossu20a4b3f2017-04-27 02:08:52 -070080 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"}}}});
oprypin92220ff2017-03-23 03:40:03 -070089 }
90
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020091 FakeNetworkPipe::Config GetNetworkPipeConfig() const override {
oprypin92220ff2017-03-23 03:40:03 -070092 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 Solenberg73276ad2017-09-14 14:46:47 +020099} // namespace
100
101using LowBandwidthAudioTest = CallTest;
102
103TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
104 AudioQualityTest test;
105 RunBaseTest(&test);
106}
oprypin92220ff2017-03-23 03:40:03 -0700107
108TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
109 Mobile2GNetworkTest test;
110 RunBaseTest(&test);
111}
oprypin92220ff2017-03-23 03:40:03 -0700112} // namespace test
113} // namespace webrtc