aboutsummaryrefslogtreecommitdiff
path: root/audio/test/audio_end_to_end_test.cc
blob: 84ad4f024001983314dd07c48cd58ef4940cdbce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <algorithm>

#include "audio/test/audio_end_to_end_test.h"
#include "system_wrappers/include/sleep.h"
#include "test/gtest.h"

namespace webrtc {
namespace test {
namespace {
// Wait half a second between stopping sending and stopping receiving audio.
constexpr int kExtraRecordTimeMs = 500;

constexpr int kSampleRate = 48000;
}  // namespace

AudioEndToEndTest::AudioEndToEndTest()
    : EndToEndTest(CallTest::kDefaultTimeoutMs) {}

FakeNetworkPipe::Config AudioEndToEndTest::GetNetworkPipeConfig() const {
  return FakeNetworkPipe::Config();
}

size_t AudioEndToEndTest::GetNumVideoStreams() const {
  return 0;
}

size_t AudioEndToEndTest::GetNumAudioStreams() const {
  return 1;
}

size_t AudioEndToEndTest::GetNumFlexfecStreams() const {
  return 0;
}

std::unique_ptr<TestAudioDeviceModule::Capturer>
AudioEndToEndTest::CreateCapturer() {
  return TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, kSampleRate);
}

std::unique_ptr<TestAudioDeviceModule::Renderer>
AudioEndToEndTest::CreateRenderer() {
  return TestAudioDeviceModule::CreateDiscardRenderer(kSampleRate);
}

void AudioEndToEndTest::OnFakeAudioDevicesCreated(
    TestAudioDeviceModule* send_audio_device,
    TestAudioDeviceModule* recv_audio_device) {
  send_audio_device_ = send_audio_device;
}

test::PacketTransport* AudioEndToEndTest::CreateSendTransport(
    SingleThreadedTaskQueueForTesting* task_queue,
    Call* sender_call) {
  return new test::PacketTransport(
      task_queue, sender_call, this, test::PacketTransport::kSender,
      test::CallTest::payload_type_map_, GetNetworkPipeConfig());
}

test::PacketTransport* AudioEndToEndTest::CreateReceiveTransport(
      SingleThreadedTaskQueueForTesting* task_queue) {
  return new test::PacketTransport(
      task_queue, nullptr, this, test::PacketTransport::kReceiver,
      test::CallTest::payload_type_map_, GetNetworkPipeConfig());
}

void AudioEndToEndTest::ModifyAudioConfigs(
  AudioSendStream::Config* send_config,
  std::vector<AudioReceiveStream::Config>* receive_configs) {
  // Large bitrate by default.
  const webrtc::SdpAudioFormat kDefaultFormat("opus", 48000, 2,
                                              {{"stereo", "1"}});
  send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
      test::CallTest::kAudioSendPayloadType, kDefaultFormat);
}

void AudioEndToEndTest::OnAudioStreamsCreated(
    AudioSendStream* send_stream,
    const std::vector<AudioReceiveStream*>& receive_streams) {
  ASSERT_NE(nullptr, send_stream);
  ASSERT_EQ(1u, receive_streams.size());
  ASSERT_NE(nullptr, receive_streams[0]);
  send_stream_ = send_stream;
  receive_stream_ = receive_streams[0];
}

void AudioEndToEndTest::PerformTest() {
  // Wait until the input audio file is done...
  send_audio_device_->WaitForRecordingEnd();
  // and some extra time to account for network delay.
  SleepMs(GetNetworkPipeConfig().queue_delay_ms + kExtraRecordTimeMs);
}
}  // namespace test
}  // namespace webrtc