audio_end_to_end_test.cc (2639B)
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 <cstddef> 14 #include <memory> 15 #include <vector> 16 17 #include "api/audio/audio_device.h" 18 #include "api/audio_codecs/audio_format.h" 19 #include "call/audio_receive_stream.h" 20 #include "call/audio_send_stream.h" 21 #include "modules/audio_device/include/test_audio_device.h" 22 #include "test/call_test.h" 23 #include "test/gtest.h" 24 #include "test/video_test_constants.h" 25 26 namespace webrtc { 27 namespace test { 28 namespace { 29 30 constexpr int kSampleRate = 48000; 31 32 } // namespace 33 34 AudioEndToEndTest::AudioEndToEndTest() 35 : EndToEndTest(VideoTestConstants::kDefaultTimeout) {} 36 37 size_t AudioEndToEndTest::GetNumVideoStreams() const { 38 return 0; 39 } 40 41 size_t AudioEndToEndTest::GetNumAudioStreams() const { 42 return 1; 43 } 44 45 size_t AudioEndToEndTest::GetNumFlexfecStreams() const { 46 return 0; 47 } 48 49 std::unique_ptr<TestAudioDeviceModule::Capturer> 50 AudioEndToEndTest::CreateCapturer() { 51 return TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, kSampleRate); 52 } 53 54 std::unique_ptr<TestAudioDeviceModule::Renderer> 55 AudioEndToEndTest::CreateRenderer() { 56 return TestAudioDeviceModule::CreateDiscardRenderer(kSampleRate); 57 } 58 59 void AudioEndToEndTest::OnFakeAudioDevicesCreated( 60 AudioDeviceModule* send_audio_device, 61 AudioDeviceModule* /* recv_audio_device */) { 62 send_audio_device_ = send_audio_device; 63 } 64 65 void AudioEndToEndTest::ModifyAudioConfigs( 66 AudioSendStream::Config* send_config, 67 std::vector<AudioReceiveStreamInterface::Config>* /* receive_configs */) { 68 // Large bitrate by default. 69 const SdpAudioFormat kDefaultFormat("opus", 48000, 2, {{"stereo", "1"}}); 70 send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec( 71 test::VideoTestConstants::kAudioSendPayloadType, kDefaultFormat); 72 send_config->min_bitrate_bps = 32000; 73 send_config->max_bitrate_bps = 32000; 74 } 75 76 void AudioEndToEndTest::OnAudioStreamsCreated( 77 AudioSendStream* send_stream, 78 const std::vector<AudioReceiveStreamInterface*>& receive_streams) { 79 ASSERT_NE(nullptr, send_stream); 80 ASSERT_EQ(1u, receive_streams.size()); 81 ASSERT_NE(nullptr, receive_streams[0]); 82 send_stream_ = send_stream; 83 receive_stream_ = receive_streams[0]; 84 } 85 86 } // namespace test 87 } // namespace webrtc