• 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 "audio/test/audio_end_to_end_test.h"
12 
13 #include <algorithm>
14 #include <memory>
15 
16 #include "api/task_queue/task_queue_base.h"
17 #include "call/fake_network_pipe.h"
18 #include "call/simulated_network.h"
19 #include "system_wrappers/include/sleep.h"
20 #include "test/gtest.h"
21 
22 namespace webrtc {
23 namespace test {
24 namespace {
25 // Wait half a second between stopping sending and stopping receiving audio.
26 constexpr int kExtraRecordTimeMs = 500;
27 
28 constexpr int kSampleRate = 48000;
29 }  // namespace
30 
AudioEndToEndTest()31 AudioEndToEndTest::AudioEndToEndTest()
32     : EndToEndTest(CallTest::kDefaultTimeout) {}
33 
GetNetworkPipeConfig() const34 BuiltInNetworkBehaviorConfig AudioEndToEndTest::GetNetworkPipeConfig() const {
35   return BuiltInNetworkBehaviorConfig();
36 }
37 
GetNumVideoStreams() const38 size_t AudioEndToEndTest::GetNumVideoStreams() const {
39   return 0;
40 }
41 
GetNumAudioStreams() const42 size_t AudioEndToEndTest::GetNumAudioStreams() const {
43   return 1;
44 }
45 
GetNumFlexfecStreams() const46 size_t AudioEndToEndTest::GetNumFlexfecStreams() const {
47   return 0;
48 }
49 
50 std::unique_ptr<TestAudioDeviceModule::Capturer>
CreateCapturer()51 AudioEndToEndTest::CreateCapturer() {
52   return TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, kSampleRate);
53 }
54 
55 std::unique_ptr<TestAudioDeviceModule::Renderer>
CreateRenderer()56 AudioEndToEndTest::CreateRenderer() {
57   return TestAudioDeviceModule::CreateDiscardRenderer(kSampleRate);
58 }
59 
OnFakeAudioDevicesCreated(TestAudioDeviceModule * send_audio_device,TestAudioDeviceModule * recv_audio_device)60 void AudioEndToEndTest::OnFakeAudioDevicesCreated(
61     TestAudioDeviceModule* send_audio_device,
62     TestAudioDeviceModule* recv_audio_device) {
63   send_audio_device_ = send_audio_device;
64 }
65 
CreateSendTransport(TaskQueueBase * task_queue,Call * sender_call)66 std::unique_ptr<test::PacketTransport> AudioEndToEndTest::CreateSendTransport(
67     TaskQueueBase* task_queue,
68     Call* sender_call) {
69   return std::make_unique<test::PacketTransport>(
70       task_queue, sender_call, this, test::PacketTransport::kSender,
71       test::CallTest::payload_type_map_,
72       std::make_unique<FakeNetworkPipe>(
73           Clock::GetRealTimeClock(),
74           std::make_unique<SimulatedNetwork>(GetNetworkPipeConfig())));
75 }
76 
77 std::unique_ptr<test::PacketTransport>
CreateReceiveTransport(TaskQueueBase * task_queue)78 AudioEndToEndTest::CreateReceiveTransport(TaskQueueBase* task_queue) {
79   return std::make_unique<test::PacketTransport>(
80       task_queue, nullptr, this, test::PacketTransport::kReceiver,
81       test::CallTest::payload_type_map_,
82       std::make_unique<FakeNetworkPipe>(
83           Clock::GetRealTimeClock(),
84           std::make_unique<SimulatedNetwork>(GetNetworkPipeConfig())));
85 }
86 
ModifyAudioConfigs(AudioSendStream::Config * send_config,std::vector<AudioReceiveStreamInterface::Config> * receive_configs)87 void AudioEndToEndTest::ModifyAudioConfigs(
88     AudioSendStream::Config* send_config,
89     std::vector<AudioReceiveStreamInterface::Config>* receive_configs) {
90   // Large bitrate by default.
91   const webrtc::SdpAudioFormat kDefaultFormat("opus", 48000, 2,
92                                               {{"stereo", "1"}});
93   send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
94       test::CallTest::kAudioSendPayloadType, kDefaultFormat);
95   send_config->min_bitrate_bps = 32000;
96   send_config->max_bitrate_bps = 32000;
97 }
98 
OnAudioStreamsCreated(AudioSendStream * send_stream,const std::vector<AudioReceiveStreamInterface * > & receive_streams)99 void AudioEndToEndTest::OnAudioStreamsCreated(
100     AudioSendStream* send_stream,
101     const std::vector<AudioReceiveStreamInterface*>& receive_streams) {
102   ASSERT_NE(nullptr, send_stream);
103   ASSERT_EQ(1u, receive_streams.size());
104   ASSERT_NE(nullptr, receive_streams[0]);
105   send_stream_ = send_stream;
106   receive_stream_ = receive_streams[0];
107 }
108 
PerformTest()109 void AudioEndToEndTest::PerformTest() {
110   // Wait until the input audio file is done...
111   send_audio_device_->WaitForRecordingEnd();
112   // and some extra time to account for network delay.
113   SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs);
114 }
115 }  // namespace test
116 }  // namespace webrtc
117