OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "audio/audio_state.h" | 13 #include "audio/audio_state.h" |
14 #include "modules/audio_mixer/audio_mixer_impl.h" | 14 #include "modules/audio_mixer/audio_mixer_impl.h" |
15 #include "modules/audio_processing/include/mock_audio_processing.h" | 15 #include "modules/audio_processing/include/mock_audio_processing.h" |
16 #include "test/gtest.h" | 16 #include "test/gtest.h" |
17 #include "test/mock_voice_engine.h" | 17 #include "test/mock_voice_engine.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace test { | 20 namespace test { |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kSampleRate = 8000; | 23 const int kSampleRate = 8000; |
24 const int kNumberOfChannels = 1; | 24 const int kNumberOfChannels = 1; |
25 const int kBytesPerSample = 2; | 25 const int kBytesPerSample = 2; |
26 | 26 |
27 struct ConfigHelper { | 27 struct ConfigHelper { |
28 ConfigHelper() : audio_mixer(AudioMixerImpl::Create()) { | 28 ConfigHelper() : audio_mixer(AudioMixerImpl::Create()) { |
29 EXPECT_CALL(mock_voice_engine, RegisterVoiceEngineObserver(testing::_)) | |
30 .WillOnce(testing::Return(0)); | |
31 EXPECT_CALL(mock_voice_engine, DeRegisterVoiceEngineObserver()) | |
32 .WillOnce(testing::Return(0)); | |
33 EXPECT_CALL(mock_voice_engine, audio_device_module()) | 29 EXPECT_CALL(mock_voice_engine, audio_device_module()) |
34 .Times(testing::AtLeast(1)); | 30 .Times(testing::AtLeast(1)); |
35 EXPECT_CALL(mock_voice_engine, audio_transport()) | 31 EXPECT_CALL(mock_voice_engine, audio_transport()) |
36 .WillRepeatedly(testing::Return(&audio_transport)); | 32 .WillRepeatedly(testing::Return(&audio_transport)); |
37 | 33 |
38 auto device = static_cast<MockAudioDeviceModule*>( | 34 auto device = static_cast<MockAudioDeviceModule*>( |
39 voice_engine().audio_device_module()); | 35 voice_engine().audio_device_module()); |
40 | 36 |
41 // Populate the audio transport proxy pointer to the most recent | 37 // Populate the audio transport proxy pointer to the most recent |
42 // transport connected to the Audio Device. | 38 // transport connected to the Audio Device. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 new internal::AudioState(helper.config())); | 90 new internal::AudioState(helper.config())); |
95 } | 91 } |
96 | 92 |
97 TEST(AudioStateTest, GetVoiceEngine) { | 93 TEST(AudioStateTest, GetVoiceEngine) { |
98 ConfigHelper helper; | 94 ConfigHelper helper; |
99 std::unique_ptr<internal::AudioState> audio_state( | 95 std::unique_ptr<internal::AudioState> audio_state( |
100 new internal::AudioState(helper.config())); | 96 new internal::AudioState(helper.config())); |
101 EXPECT_EQ(audio_state->voice_engine(), &helper.voice_engine()); | 97 EXPECT_EQ(audio_state->voice_engine(), &helper.voice_engine()); |
102 } | 98 } |
103 | 99 |
104 TEST(AudioStateTest, TypingNoiseDetected) { | |
105 ConfigHelper helper; | |
106 std::unique_ptr<internal::AudioState> audio_state( | |
107 new internal::AudioState(helper.config())); | |
108 VoiceEngineObserver* voe_observer = | |
109 static_cast<VoiceEngineObserver*>(audio_state.get()); | |
110 EXPECT_FALSE(audio_state->typing_noise_detected()); | |
111 | |
112 voe_observer->CallbackOnError(-1, VE_NOT_INITED); | |
113 EXPECT_FALSE(audio_state->typing_noise_detected()); | |
114 | |
115 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); | |
116 EXPECT_TRUE(audio_state->typing_noise_detected()); | |
117 voe_observer->CallbackOnError(-1, VE_NOT_INITED); | |
118 EXPECT_TRUE(audio_state->typing_noise_detected()); | |
119 | |
120 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); | |
121 EXPECT_FALSE(audio_state->typing_noise_detected()); | |
122 voe_observer->CallbackOnError(-1, VE_NOT_INITED); | |
123 EXPECT_FALSE(audio_state->typing_noise_detected()); | |
124 } | |
125 | |
126 // Test that RecordedDataIsAvailable calls get to the original transport. | 100 // Test that RecordedDataIsAvailable calls get to the original transport. |
127 TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { | 101 TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { |
128 ConfigHelper helper; | 102 ConfigHelper helper; |
129 | 103 |
130 rtc::scoped_refptr<AudioState> audio_state = | 104 rtc::scoped_refptr<AudioState> audio_state = |
131 AudioState::Create(helper.config()); | 105 AudioState::Create(helper.config()); |
132 | 106 |
133 // Setup completed. Ensure call of original transport is forwarded to new. | 107 // Setup completed. Ensure call of original transport is forwarded to new. |
134 uint32_t new_mic_level; | 108 uint32_t new_mic_level; |
135 EXPECT_CALL( | 109 EXPECT_CALL( |
(...skipping 30 matching lines...) Expand all Loading... |
166 int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels]; | 140 int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels]; |
167 size_t n_samples_out; | 141 size_t n_samples_out; |
168 int64_t elapsed_time_ms; | 142 int64_t elapsed_time_ms; |
169 int64_t ntp_time_ms; | 143 int64_t ntp_time_ms; |
170 helper.audio_transport_proxy()->NeedMorePlayData( | 144 helper.audio_transport_proxy()->NeedMorePlayData( |
171 kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, | 145 kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, |
172 audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); | 146 audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); |
173 } | 147 } |
174 } // namespace test | 148 } // namespace test |
175 } // namespace webrtc | 149 } // namespace webrtc |
OLD | NEW |