From eb98c727e616c548d654e5543116110e22a9d0ee Mon Sep 17 00:00:00 2001 From: henrika Date: Tue, 20 Mar 2018 12:54:07 +0100 Subject: [PATCH] Minor improvements in ADM unittest for Windows. This CL resolves some minor issues related to running ADM unittests on Windows. It is rather common on Windows that devices can't be opened up in mono mode and some tests have been hardcoded to use mono and that leads to crashes and/or error logs. Now, all tests runs in stereo as well. NOTRY=TRUE Bug: None Change-Id: Iebf11a6ff63c19ff1be45575a8e0a3df4e112bd4 Reviewed-on: https://webrtc-review.googlesource.com/62940 Commit-Queue: Henrik Andreassson Reviewed-by: Oskar Sundbom Cr-Commit-Position: refs/heads/master@{#22510} --- modules/audio_device/audio_device_unittest.cc | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/modules/audio_device/audio_device_unittest.cc b/modules/audio_device/audio_device_unittest.cc index ccdc004bbd..f4893c587b 100644 --- a/modules/audio_device/audio_device_unittest.cc +++ b/modules/audio_device/audio_device_unittest.cc @@ -94,8 +94,8 @@ enum class TransportType { // measurements. class AudioStream { public: - virtual void Write(rtc::ArrayView source, size_t channels) = 0; - virtual void Read(rtc::ArrayView destination, size_t channels) = 0; + virtual void Write(rtc::ArrayView source) = 0; + virtual void Read(rtc::ArrayView destination) = 0; virtual ~AudioStream() = default; }; @@ -122,8 +122,7 @@ int IndexToMilliseconds(size_t index, size_t frames_per_10ms_buffer) { // change over time and that both sides will use the same size. class FifoAudioStream : public AudioStream { public: - void Write(rtc::ArrayView source, size_t channels) override { - EXPECT_EQ(channels, 1u); + void Write(rtc::ArrayView source) override { RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); const size_t size = [&] { rtc::CritScope lock(&lock_); @@ -140,8 +139,7 @@ class FifoAudioStream : public AudioStream { written_elements_ += size; } - void Read(rtc::ArrayView destination, size_t channels) override { - EXPECT_EQ(channels, 1u); + void Read(rtc::ArrayView destination) override { rtc::CritScope lock(&lock_); if (fifo_.empty()) { std::fill(destination.begin(), destination.end(), 0); @@ -191,9 +189,8 @@ class LatencyAudioStream : public AudioStream { } // Insert periodic impulses in first two samples of |destination|. - void Read(rtc::ArrayView destination, size_t channels) override { + void Read(rtc::ArrayView destination) override { RTC_DCHECK_RUN_ON(&read_thread_checker_); - EXPECT_EQ(channels, 1u); if (read_count_ == 0) { PRINT("["); } @@ -214,8 +211,7 @@ class LatencyAudioStream : public AudioStream { // Detect received impulses in |source|, derive time between transmission and // detection and add the calculated delay to list of latencies. - void Write(rtc::ArrayView source, size_t channels) override { - EXPECT_EQ(channels, 1u); + void Write(rtc::ArrayView source) override { RTC_DCHECK_RUN_ON(&write_thread_checker_); RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); rtc::CritScope lock(&lock_); @@ -360,8 +356,7 @@ class MockAudioTransport : public test::MockAudioTransport { if (audio_stream_) { audio_stream_->Write( rtc::MakeArrayView(static_cast(audio_buffer), - samples_per_channel * channels), - channels); + samples_per_channel * channels)); } // Signal the event after given amount of callbacks. if (ReceivedEnoughCallbacks()) { @@ -375,7 +370,7 @@ class MockAudioTransport : public test::MockAudioTransport { const size_t channels, const uint32_t sample_rate, void* audio_buffer, - size_t& samples_per_channel_out, + size_t& samples_out, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) { EXPECT_TRUE(play_mode()) << "No test is expecting these callbacks."; @@ -395,13 +390,11 @@ class MockAudioTransport : public test::MockAudioTransport { playout_parameters_.frames_per_10ms_buffer()); } play_count_++; - samples_per_channel_out = samples_per_channel; + samples_out = samples_per_channel * channels; // Read audio data from audio stream object if one has been injected. if (audio_stream_) { - audio_stream_->Read( - rtc::MakeArrayView(static_cast(audio_buffer), - samples_per_channel * channels), - channels); + audio_stream_->Read(rtc::MakeArrayView( + static_cast(audio_buffer), samples_per_channel * channels)); } else { // Fill the audio buffer with zeros to avoid disturbing audio. const size_t num_bytes = samples_per_channel * bytes_per_frame; @@ -693,11 +686,11 @@ TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { mock.HandleCallbacks(event(), &audio_stream, kFullDuplexTimeInSec * kNumCallbacksPerSecond); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); - // Run both sides in mono to make the loopback packet handling less complex. - // The test works for stereo as well; the only requirement is that both sides - // use the same configuration. - EXPECT_EQ(0, audio_device()->SetStereoPlayout(false)); - EXPECT_EQ(0, audio_device()->SetStereoRecording(false)); + // Run both sides using the same channel configuration to avoid conversions + // between mono/stereo while running in full duplex mode. Also, some devices + // (mainly on Windows) do not support mono. + EXPECT_EQ(0, audio_device()->SetStereoPlayout(true)); + EXPECT_EQ(0, audio_device()->SetStereoRecording(true)); StartPlayout(); StartRecording(); event()->Wait(static_cast( @@ -730,8 +723,8 @@ TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) { mock.HandleCallbacks(event(), &audio_stream, kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); - EXPECT_EQ(0, audio_device()->SetStereoPlayout(false)); - EXPECT_EQ(0, audio_device()->SetStereoRecording(false)); + EXPECT_EQ(0, audio_device()->SetStereoPlayout(true)); + EXPECT_EQ(0, audio_device()->SetStereoRecording(true)); StartPlayout(); StartRecording(); event()->Wait(static_cast(