• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
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 
11 #include "absl/flags/declare.h"
12 #include "absl/flags/flag.h"
13 #include "api/test/simulated_network.h"
14 #include "audio/test/audio_end_to_end_test.h"
15 #include "system_wrappers/include/sleep.h"
16 #include "test/testsupport/file_utils.h"
17 
18 ABSL_DECLARE_FLAG(int, sample_rate_hz);
19 ABSL_DECLARE_FLAG(bool, quick);
20 
21 namespace webrtc {
22 namespace test {
23 namespace {
24 
FileSampleRateSuffix()25 std::string FileSampleRateSuffix() {
26   return std::to_string(absl::GetFlag(FLAGS_sample_rate_hz) / 1000);
27 }
28 
29 class AudioQualityTest : public AudioEndToEndTest {
30  public:
31   AudioQualityTest() = default;
32 
33  private:
AudioInputFile() const34   std::string AudioInputFile() const {
35     return test::ResourcePath(
36         "voice_engine/audio_tiny" + FileSampleRateSuffix(), "wav");
37   }
38 
AudioOutputFile() const39   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() +
43            "_" + FileSampleRateSuffix() + ".wav";
44   }
45 
CreateCapturer()46   std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
47     return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
48   }
49 
CreateRenderer()50   std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
51     return TestAudioDeviceModule::CreateBoundedWavFileWriter(
52         AudioOutputFile(), absl::GetFlag(FLAGS_sample_rate_hz));
53   }
54 
PerformTest()55   void PerformTest() override {
56     if (absl::GetFlag(FLAGS_quick)) {
57       // 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   }
63 
OnStreamsStopped()64   void OnStreamsStopped() override {
65     const ::testing::TestInfo* const test_info =
66         ::testing::UnitTest::GetInstance()->current_test_info();
67 
68     // Output information about the input and output audio files so that further
69     // processing can be done by an external process.
70     printf("TEST %s %s %s\n", test_info->name(), AudioInputFile().c_str(),
71            AudioOutputFile().c_str());
72   }
73 };
74 
75 class Mobile2GNetworkTest : public AudioQualityTest {
ModifyAudioConfigs(AudioSendStream::Config * send_config,std::vector<AudioReceiveStream::Config> * receive_configs)76   void ModifyAudioConfigs(
77       AudioSendStream::Config* send_config,
78       std::vector<AudioReceiveStream::Config>* receive_configs) override {
79     send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
80         test::CallTest::kAudioSendPayloadType,
81         {"OPUS",
82          48000,
83          2,
84          {{"maxaveragebitrate", "6000"}, {"ptime", "60"}, {"stereo", "1"}}});
85   }
86 
GetNetworkPipeConfig() const87   BuiltInNetworkBehaviorConfig GetNetworkPipeConfig() const override {
88     BuiltInNetworkBehaviorConfig pipe_config;
89     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 };
95 }  // namespace
96 
97 using LowBandwidthAudioTest = CallTest;
98 
TEST_F(LowBandwidthAudioTest,GoodNetworkHighBitrate)99 TEST_F(LowBandwidthAudioTest, GoodNetworkHighBitrate) {
100   AudioQualityTest test;
101   RunBaseTest(&test);
102 }
103 
TEST_F(LowBandwidthAudioTest,Mobile2GNetwork)104 TEST_F(LowBandwidthAudioTest, Mobile2GNetwork) {
105   Mobile2GNetworkTest test;
106   RunBaseTest(&test);
107 }
108 }  // namespace test
109 }  // namespace webrtc
110