Index: webrtc/audio/audio_state_unittest.cc |
diff --git a/webrtc/audio/audio_state_unittest.cc b/webrtc/audio/audio_state_unittest.cc |
index 38485a88bf14665ce6b15d9a149cefec6513751f..05c5003459e94292af27d8eee45e289efb322e65 100644 |
--- a/webrtc/audio/audio_state_unittest.cc |
+++ b/webrtc/audio/audio_state_unittest.cc |
@@ -19,26 +19,65 @@ namespace webrtc { |
namespace test { |
namespace { |
+const int kSampleRate = 8000; |
+const int kNumberOfChannels = 1; |
+const int kBytesPerSample = 2; |
+ |
struct ConfigHelper { |
- ConfigHelper() { |
- EXPECT_CALL(voice_engine_, |
- RegisterVoiceEngineObserver(testing::_)).WillOnce(testing::Return(0)); |
- EXPECT_CALL(voice_engine_, |
- DeRegisterVoiceEngineObserver()).WillOnce(testing::Return(0)); |
- EXPECT_CALL(voice_engine_, audio_device_module()); |
- EXPECT_CALL(voice_engine_, audio_processing()); |
- EXPECT_CALL(voice_engine_, audio_transport()); |
- |
- config_.voice_engine = &voice_engine_; |
- config_.audio_mixer = AudioMixerImpl::Create(); |
+ ConfigHelper() : audio_mixer(AudioMixerImpl::Create()) { |
+ EXPECT_CALL(mock_voice_engine, RegisterVoiceEngineObserver(testing::_)) |
+ .WillOnce(testing::Return(0)); |
+ EXPECT_CALL(mock_voice_engine, DeRegisterVoiceEngineObserver()) |
+ .WillOnce(testing::Return(0)); |
+ EXPECT_CALL(mock_voice_engine, audio_device_module()) |
+ .Times(testing::AtLeast(1)); |
+ EXPECT_CALL(mock_voice_engine, audio_processing()) |
+ .Times(testing::AtLeast(1)); |
+ EXPECT_CALL(mock_voice_engine, audio_transport()) |
+ .WillRepeatedly(testing::Return(&audio_transport)); |
+ |
+ auto device = static_cast<MockAudioDeviceModule*>( |
+ voice_engine().audio_device_module()); |
+ |
+ // Populate the audio transport proxy pointer to the most recent |
+ // transport connected to the Audio Device. |
+ ON_CALL(*device, RegisterAudioCallback(testing::_)) |
+ .WillByDefault(testing::Invoke([this](AudioTransport* transport) { |
+ registered_audio_transport = transport; |
+ return 0; |
+ })); |
+ |
+ audio_state_config.voice_engine = &mock_voice_engine; |
+ audio_state_config.audio_mixer = audio_mixer; |
} |
- AudioState::Config& config() { return config_; } |
- MockVoiceEngine& voice_engine() { return voice_engine_; } |
+ AudioState::Config& config() { return audio_state_config; } |
+ MockVoiceEngine& voice_engine() { return mock_voice_engine; } |
+ rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer; } |
+ MockAudioTransport& original_audio_transport() { return audio_transport; } |
+ AudioTransport* audio_transport_proxy() { return registered_audio_transport; } |
private: |
- testing::StrictMock<MockVoiceEngine> voice_engine_; |
- AudioState::Config config_; |
+ testing::StrictMock<MockVoiceEngine> mock_voice_engine; |
+ AudioState::Config audio_state_config; |
+ rtc::scoped_refptr<AudioMixer> audio_mixer; |
+ MockAudioTransport audio_transport; |
+ AudioTransport* registered_audio_transport = nullptr; |
+}; |
+ |
+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(AudioStateTest, Create) { |
@@ -84,38 +123,52 @@ TEST(AudioStateTest, TypingNoiseDetected) { |
} |
// Test that RecordedDataIsAvailable calls get to the original transport. |
-TEST(AudioStateTest, RecordedAudioArrivesAtOriginalTransport) { |
- using testing::_; |
+TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { |
+ ConfigHelper helper; |
+ 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))); |
+ |
+ helper.audio_transport_proxy()->RecordedDataIsAvailable( |
+ nullptr, kSampleRate / 100, kBytesPerSample, kNumberOfChannels, |
+ kSampleRate, 0, 0, 0, false, new_mic_level); |
+} |
+ |
+TEST(AudioStateAudioPathTest, |
+ QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { |
ConfigHelper helper; |
- auto& voice_engine = helper.voice_engine(); |
- auto device = |
- static_cast<MockAudioDeviceModule*>(voice_engine.audio_device_module()); |
- |
- AudioTransport* audio_transport_proxy = nullptr; |
- ON_CALL(*device, RegisterAudioCallback(_)) |
- .WillByDefault( |
- testing::Invoke([&audio_transport_proxy](AudioTransport* transport) { |
- audio_transport_proxy = transport; |
- return 0; |
- })); |
- MockAudioTransport original_audio_transport; |
- ON_CALL(voice_engine, audio_transport()) |
- .WillByDefault(testing::Return(&original_audio_transport)); |
+ rtc::scoped_refptr<AudioState> audio_state = |
+ AudioState::Create(helper.config()); |
+ |
+ FakeAudioSource fake_source; |
- EXPECT_CALL(voice_engine, audio_device_module()); |
- std::unique_ptr<internal::AudioState> audio_state( |
- new internal::AudioState(helper.config())); |
+ helper.mixer()->AddSource(&fake_source); |
- // Setup completed. Ensure call of old transport is forwarded to new. |
- uint32_t new_mic_level; |
- EXPECT_CALL(original_audio_transport, |
- RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false, |
- testing::Ref(new_mic_level))); |
+ 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; |
+ })); |
- audio_transport_proxy->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, |
- 0, false, new_mic_level); |
+ int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels]; |
+ size_t n_samples_out; |
+ int64_t elapsed_time_ms; |
+ int64_t ntp_time_ms; |
+ helper.audio_transport_proxy()->NeedMorePlayData( |
+ kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, |
+ audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); |
} |
} // namespace test |
} // namespace webrtc |