Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(936)

Unified Diff: webrtc/audio/audio_state_audio_path_unittest.cc

Issue 2436033002: Replace AudioConferenceMixer with AudioMixer. (Closed)
Patch Set: Declare constants and depend on RemoveSource CL. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/audio/audio_state_audio_path_unittest.cc
diff --git a/webrtc/audio/audio_state_audio_path_unittest.cc b/webrtc/audio/audio_state_audio_path_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6789af9b1d39953b8aec6fca9cd66636df09c31
--- /dev/null
+++ b/webrtc/audio/audio_state_audio_path_unittest.cc
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2016 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 <memory>
+
+#include "webrtc/audio/audio_state.h"
+#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
+#include "webrtc/test/gtest.h"
+#include "webrtc/test/mock_voice_engine.h"
+
+namespace webrtc {
+namespace test {
+namespace {
+
+const int kSampleRate = 8000;
+const int kNumberOfChannels = 1;
+const int kBytesPerSample = 2;
+
+struct ConfigHelper {
+ ConfigHelper() : audio_mixer_(AudioMixerImpl::Create()) {
+ using testing::_;
+
+ EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_))
+ .WillOnce(testing::Return(0));
+ EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver())
+ .WillOnce(testing::Return(0));
+ EXPECT_CALL(voice_engine_, audio_processing());
+ EXPECT_CALL(voice_engine_, audio_transport());
+
+ ON_CALL(voice_engine_, audio_transport())
+ .WillByDefault(testing::Return(&audio_transport_));
+
+ config_.voice_engine = &voice_engine_;
+ config_.audio_mixer = audio_mixer_;
+ }
+
+ rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; }
+
+ MockAudioTransport& original_audio_transport() { return audio_transport_; }
+
+ AudioState::Config& config() { return config_; }
+ MockVoiceEngine& voice_engine() { return voice_engine_; }
+
the sun 2016/11/18 16:30:17 private:
aleloi 2016/11/21 11:59:11 Done.
+ testing::StrictMock<MockVoiceEngine> voice_engine_;
+ MockAudioTransport audio_transport_;
+ rtc::scoped_refptr<AudioMixer> audio_mixer_;
+ AudioState::Config config_;
+};
+
+class FakeAudioSource : public AudioMixer::Source {
+ public:
+ // TODO(aleloi): Valid overrides commented out, because the gmock
+ // methods don't use any override declarations, and we want to avoid
+ // warnings from -Winconsistent-missing-override. See
+ // http://crbug.com/428099.
+ int Ssrc() const /*override*/ { return 0; }
+
+ int PreferredSampleRate() const /*override*/ { return kSampleRate; }
+
+ MOCK_METHOD2(GetAudioFrameWithInfo,
+ AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame));
+};
+} // namespace
+
+// Test that RecordedDataIsAvailable calls get to the original transport.
+TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) {
+ ConfigHelper helper;
+
+ EXPECT_CALL(helper.voice_engine(), audio_device_module()).Times(2);
+ auto device = static_cast<MockAudioDeviceModule*>(
+ helper.voice_engine().audio_device_module());
+
+ // Get a local pointer to the most recent transport connected to the
+ // Audio Device.
+ AudioTransport* audio_transport_proxy = nullptr;
+ ON_CALL(*device, RegisterAudioCallback(testing::_))
+ .WillByDefault(
+ testing::Invoke([&audio_transport_proxy](AudioTransport* transport) {
+ audio_transport_proxy = transport;
+ return 0;
+ }));
+
+ rtc::scoped_refptr<AudioState> audio_state =
+ AudioState::Create(helper.config());
+
+ // Setup completed. Ensure call of original transport is forwarded to new.
+ uint32_t new_mic_level;
+ EXPECT_CALL(
+ helper.original_audio_transport(),
+ RecordedDataIsAvailable(nullptr, kSampleRate / 100, kBytesPerSample,
+ kNumberOfChannels, kSampleRate, 0, 0, 0, false,
+ testing::Ref(new_mic_level)));
+
+ audio_transport_proxy->RecordedDataIsAvailable(
+ nullptr, kSampleRate / 100, kBytesPerSample, kNumberOfChannels,
+ kSampleRate, 0, 0, 0, false, new_mic_level);
+}
+
+TEST(AudioStateAudioPathTest,
+ QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) {
+ ConfigHelper helper;
+
+ EXPECT_CALL(helper.voice_engine(), audio_device_module()).Times(2);
the sun 2016/11/18 16:30:17 Are you sure you couldn't have line 110-123 in the
aleloi 2016/11/21 11:59:11 Done. I was initially reluctant to do that: I thou
+ auto device = static_cast<MockAudioDeviceModule*>(
+ helper.voice_engine().audio_device_module());
+
+ AudioTransport* audio_transport_proxy = nullptr;
+ ON_CALL(*device, RegisterAudioCallback(testing::_))
+ .WillByDefault(
+ testing::Invoke([&audio_transport_proxy](AudioTransport* transport) {
+ audio_transport_proxy = transport;
+ return 0;
+ }));
+
+ rtc::scoped_refptr<AudioState> audio_state =
+ AudioState::Create(helper.config());
+
+ FakeAudioSource fake_source;
+
+ helper.mixer()->AddSource(&fake_source);
+
+ EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_))
+ .WillOnce(
+ testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) {
+ audio_frame->sample_rate_hz_ = sample_rate_hz;
+ audio_frame->samples_per_channel_ = sample_rate_hz / 100;
+ audio_frame->num_channels_ = kNumberOfChannels;
+ return AudioMixer::Source::AudioFrameInfo::kNormal;
+ }));
+
+ int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels];
+ size_t n_samples_out;
+ int64_t elapsed_time_ms;
+ int64_t ntp_time_ms;
+ audio_transport_proxy->NeedMorePlayData(
+ kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate,
+ audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms);
+}
+} // namespace test
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698