diff --git a/audio/BUILD.gn b/audio/BUILD.gn index d1a42b6d6d..c0b0d62d93 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -134,6 +134,8 @@ if (rtc_include_tests) { "../api/task_queue", "../call:fake_network", "../call:simulated_network", + "../modules/audio_device:audio_device_api", + "../modules/audio_device:audio_device_impl", "../system_wrappers", "../test:test_common", "../test:test_support", diff --git a/audio/test/audio_end_to_end_test.cc b/audio/test/audio_end_to_end_test.cc index b7dfdb89f6..97acf93c1b 100644 --- a/audio/test/audio_end_to_end_test.cc +++ b/audio/test/audio_end_to_end_test.cc @@ -16,16 +16,16 @@ #include "api/task_queue/task_queue_base.h" #include "call/fake_network_pipe.h" #include "call/simulated_network.h" +#include "modules/audio_device/include/test_audio_device.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() @@ -54,8 +54,8 @@ AudioEndToEndTest::CreateRenderer() { } void AudioEndToEndTest::OnFakeAudioDevicesCreated( - TestAudioDeviceModule* send_audio_device, - TestAudioDeviceModule* recv_audio_device) { + AudioDeviceModule* send_audio_device, + AudioDeviceModule* recv_audio_device) { send_audio_device_ = send_audio_device; } @@ -81,11 +81,5 @@ void AudioEndToEndTest::OnAudioStreamsCreated( 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(GetSendTransportConfig().queue_delay_ms + kExtraRecordTimeMs); -} } // namespace test } // namespace webrtc diff --git a/audio/test/audio_end_to_end_test.h b/audio/test/audio_end_to_end_test.h index 607fe692be..d326b790ff 100644 --- a/audio/test/audio_end_to_end_test.h +++ b/audio/test/audio_end_to_end_test.h @@ -16,6 +16,8 @@ #include "api/task_queue/task_queue_base.h" #include "api/test/simulated_network.h" +#include "modules/audio_device/include/audio_device.h" +#include "modules/audio_device/include/test_audio_device.h" #include "test/call_test.h" namespace webrtc { @@ -26,7 +28,7 @@ class AudioEndToEndTest : public test::EndToEndTest { AudioEndToEndTest(); protected: - TestAudioDeviceModule* send_audio_device() { return send_audio_device_; } + AudioDeviceModule* send_audio_device() { return send_audio_device_; } const AudioSendStream* send_stream() const { return send_stream_; } const AudioReceiveStreamInterface* receive_stream() const { return receive_stream_; @@ -39,9 +41,8 @@ class AudioEndToEndTest : public test::EndToEndTest { std::unique_ptr CreateCapturer() override; std::unique_ptr CreateRenderer() override; - void OnFakeAudioDevicesCreated( - TestAudioDeviceModule* send_audio_device, - TestAudioDeviceModule* recv_audio_device) override; + void OnFakeAudioDevicesCreated(AudioDeviceModule* send_audio_device, + AudioDeviceModule* recv_audio_device) override; void ModifyAudioConfigs(AudioSendStream::Config* send_config, std::vector* @@ -50,10 +51,8 @@ class AudioEndToEndTest : public test::EndToEndTest { const std::vector& receive_streams) override; - void PerformTest() override; - private: - TestAudioDeviceModule* send_audio_device_ = nullptr; + AudioDeviceModule* send_audio_device_ = nullptr; AudioSendStream* send_stream_ = nullptr; AudioReceiveStreamInterface* receive_stream_ = nullptr; }; diff --git a/audio/test/audio_stats_test.cc b/audio/test/audio_stats_test.cc index 1c81432574..2aae2d9c14 100644 --- a/audio/test/audio_stats_test.cc +++ b/audio/test/audio_stats_test.cc @@ -17,6 +17,9 @@ namespace webrtc { namespace test { namespace { +// Wait half a second between stopping sending and stopping receiving audio. +constexpr int kExtraRecordTimeMs = 500; + bool IsNear(int reference, int v) { // Margin is 10%. const int error = reference / 10 + 1; @@ -41,7 +44,8 @@ class NoLossTest : public AudioEndToEndTest { void PerformTest() override { SleepMs(kTestDurationMs); send_audio_device()->StopRecording(); - AudioEndToEndTest::PerformTest(); + // and some extra time to account for network delay. + SleepMs(GetSendTransportConfig().queue_delay_ms + kExtraRecordTimeMs); } void OnStreamsStopped() override { diff --git a/audio/test/low_bandwidth_audio_test.cc b/audio/test/low_bandwidth_audio_test.cc index f385eb9dcc..3cc90f7fb8 100644 --- a/audio/test/low_bandwidth_audio_test.cc +++ b/audio/test/low_bandwidth_audio_test.cc @@ -57,7 +57,8 @@ class AudioQualityTest : public AudioEndToEndTest { // Let the recording run for a small amount of time to check if it works. SleepMs(1000); } else { - AudioEndToEndTest::PerformTest(); + // Sleep for whole audio duration which is 5.4 seconds. + SleepMs(5400); } } diff --git a/modules/audio_device/include/test_audio_device.cc b/modules/audio_device/include/test_audio_device.cc index eacded7728..76406448a0 100644 --- a/modules/audio_device/include/test_audio_device.cc +++ b/modules/audio_device/include/test_audio_device.cc @@ -439,7 +439,7 @@ size_t TestAudioDeviceModule::SamplesPerFrame(int sampling_frequency_in_hz) { return rtc::CheckedDivExact(sampling_frequency_in_hz, kFramesPerSecond); } -rtc::scoped_refptr TestAudioDeviceModule::Create( +rtc::scoped_refptr TestAudioDeviceModule::Create( TaskQueueFactory* task_queue_factory, std::unique_ptr capturer, std::unique_ptr renderer, diff --git a/modules/audio_device/include/test_audio_device.h b/modules/audio_device/include/test_audio_device.h index e52e93c525..87ba9cfbae 100644 --- a/modules/audio_device/include/test_audio_device.h +++ b/modules/audio_device/include/test_audio_device.h @@ -82,7 +82,7 @@ class TestAudioDeviceModule : public AudioDeviceModule { // `renderer` is an object that receives audio data that would have been // played out. Can be nullptr if this device is never used for playing. // Use one of the Create... functions to get these instances. - static rtc::scoped_refptr Create( + static rtc::scoped_refptr Create( TaskQueueFactory* task_queue_factory, std::unique_ptr capturer, std::unique_ptr renderer, diff --git a/test/BUILD.gn b/test/BUILD.gn index aa418b462e..ea2c669626 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1099,6 +1099,7 @@ rtc_library("test_common") { "../call:simulated_network", "../call:simulated_packet_receiver", "../call:video_stream_api", + "../modules/audio_device:audio_device_api", "../modules/audio_device:audio_device_impl", "../modules/audio_mixer:audio_mixer_impl", "../modules/rtp_rtcp", diff --git a/test/call_test.cc b/test/call_test.cc index 5fc7feb3c0..b6b633f94b 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -22,6 +22,8 @@ #include "call/fake_network_pipe.h" #include "call/packet_receiver.h" #include "call/simulated_network.h" +#include "modules/audio_device/include/audio_device.h" +#include "modules/audio_device/include/test_audio_device.h" #include "modules/audio_mixer/audio_mixer_impl.h" #include "rtc_base/checks.h" #include "rtc_base/event.h" @@ -770,9 +772,9 @@ std::unique_ptr BaseTest::CreateRenderer() { return TestAudioDeviceModule::CreateDiscardRenderer(48000); } -void BaseTest::OnFakeAudioDevicesCreated( - TestAudioDeviceModule* send_audio_device, - TestAudioDeviceModule* recv_audio_device) {} +void BaseTest::OnFakeAudioDevicesCreated(AudioDeviceModule* send_audio_device, + AudioDeviceModule* recv_audio_device) { +} void BaseTest::ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) {} diff --git a/test/call_test.h b/test/call_test.h index 3324bc4b5e..d6acfefb87 100644 --- a/test/call_test.h +++ b/test/call_test.h @@ -26,6 +26,7 @@ #include "api/units/time_delta.h" #include "api/video/video_bitrate_allocator_factory.h" #include "call/call.h" +#include "modules/audio_device/include/audio_device.h" #include "modules/audio_device/include/test_audio_device.h" #include "test/encoder_settings.h" #include "test/fake_decoder.h" @@ -271,8 +272,8 @@ class CallTest : public ::testing::Test, public RtpPacketSinkInterface { std::vector rtp_extensions_; rtc::scoped_refptr apm_send_; rtc::scoped_refptr apm_recv_; - rtc::scoped_refptr fake_send_audio_device_; - rtc::scoped_refptr fake_recv_audio_device_; + rtc::scoped_refptr fake_send_audio_device_; + rtc::scoped_refptr fake_recv_audio_device_; }; class BaseTest : public RtpRtcpObserver { @@ -290,9 +291,8 @@ class BaseTest : public RtpRtcpObserver { virtual std::unique_ptr CreateCapturer(); virtual std::unique_ptr CreateRenderer(); - virtual void OnFakeAudioDevicesCreated( - TestAudioDeviceModule* send_audio_device, - TestAudioDeviceModule* recv_audio_device); + virtual void OnFakeAudioDevicesCreated(AudioDeviceModule* send_audio_device, + AudioDeviceModule* recv_audio_device); virtual void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config); virtual void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config);