blob: 8ba9a047f3602f8e552c3871a40545dc5d77959a [file] [log] [blame]
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02001/*
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 <algorithm>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "audio/test/audio_end_to_end_test.h"
14#include "system_wrappers/include/sleep.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/gtest.h"
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020016
17namespace webrtc {
18namespace test {
19namespace {
20// Wait half a second between stopping sending and stopping receiving audio.
21constexpr int kExtraRecordTimeMs = 500;
22
23constexpr int kSampleRate = 48000;
24} // namespace
25
26AudioEndToEndTest::AudioEndToEndTest()
27 : EndToEndTest(CallTest::kDefaultTimeoutMs) {}
28
Artem Titov46c4e602018-08-17 14:26:54 +020029DefaultNetworkSimulationConfig AudioEndToEndTest::GetNetworkPipeConfig() const {
30 return DefaultNetworkSimulationConfig();
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020031}
32
33size_t AudioEndToEndTest::GetNumVideoStreams() const {
34 return 0;
35}
36
37size_t AudioEndToEndTest::GetNumAudioStreams() const {
38 return 1;
39}
40
41size_t AudioEndToEndTest::GetNumFlexfecStreams() const {
42 return 0;
43}
44
Artem Titov3faa8322018-03-07 14:44:00 +010045std::unique_ptr<TestAudioDeviceModule::Capturer>
46AudioEndToEndTest::CreateCapturer() {
47 return TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, kSampleRate);
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020048}
49
Artem Titov3faa8322018-03-07 14:44:00 +010050std::unique_ptr<TestAudioDeviceModule::Renderer>
51AudioEndToEndTest::CreateRenderer() {
52 return TestAudioDeviceModule::CreateDiscardRenderer(kSampleRate);
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020053}
54
55void AudioEndToEndTest::OnFakeAudioDevicesCreated(
Artem Titov3faa8322018-03-07 14:44:00 +010056 TestAudioDeviceModule* send_audio_device,
57 TestAudioDeviceModule* recv_audio_device) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020058 send_audio_device_ = send_audio_device;
59}
60
61test::PacketTransport* AudioEndToEndTest::CreateSendTransport(
62 SingleThreadedTaskQueueForTesting* task_queue,
63 Call* sender_call) {
64 return new test::PacketTransport(
65 task_queue, sender_call, this, test::PacketTransport::kSender,
66 test::CallTest::payload_type_map_, GetNetworkPipeConfig());
67}
68
69test::PacketTransport* AudioEndToEndTest::CreateReceiveTransport(
Yves Gerey665174f2018-06-19 15:03:05 +020070 SingleThreadedTaskQueueForTesting* task_queue) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020071 return new test::PacketTransport(
72 task_queue, nullptr, this, test::PacketTransport::kReceiver,
73 test::CallTest::payload_type_map_, GetNetworkPipeConfig());
74}
75
76void AudioEndToEndTest::ModifyAudioConfigs(
Yves Gerey665174f2018-06-19 15:03:05 +020077 AudioSendStream::Config* send_config,
78 std::vector<AudioReceiveStream::Config>* receive_configs) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020079 // Large bitrate by default.
80 const webrtc::SdpAudioFormat kDefaultFormat("opus", 48000, 2,
81 {{"stereo", "1"}});
Oskar Sundbom2707fb22017-11-16 10:57:35 +010082 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
83 test::CallTest::kAudioSendPayloadType, kDefaultFormat);
Fredrik Solenberg73276ad2017-09-14 14:46:47 +020084}
85
86void AudioEndToEndTest::OnAudioStreamsCreated(
87 AudioSendStream* send_stream,
88 const std::vector<AudioReceiveStream*>& receive_streams) {
89 ASSERT_NE(nullptr, send_stream);
90 ASSERT_EQ(1u, receive_streams.size());
91 ASSERT_NE(nullptr, receive_streams[0]);
92 send_stream_ = send_stream;
93 receive_stream_ = receive_streams[0];
94}
95
96void AudioEndToEndTest::PerformTest() {
97 // Wait until the input audio file is done...
98 send_audio_device_->WaitForRecordingEnd();
99 // and some extra time to account for network delay.
100 SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs);
101}
102} // namespace test
103} // namespace webrtc