OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <memory> | |
12 | |
13 #include "webrtc/audio/audio_state.h" | |
14 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | |
15 #include "webrtc/test/gtest.h" | |
16 #include "webrtc/test/mock_voice_engine.h" | |
17 | |
18 namespace webrtc { | |
19 namespace test { | |
20 namespace { | |
21 | |
22 const int kSampleRate = 8000; | |
23 const int kNumberOfChannels = 1; | |
24 const int kBytesPerSample = 2; | |
25 | |
26 struct ConfigHelper { | |
27 ConfigHelper() : audio_mixer_(AudioMixerImpl::Create()) { | |
28 using testing::_; | |
29 | |
30 EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_)) | |
31 .WillOnce(testing::Return(0)); | |
32 EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver()) | |
33 .WillOnce(testing::Return(0)); | |
34 EXPECT_CALL(voice_engine_, audio_processing()); | |
35 EXPECT_CALL(voice_engine_, audio_transport()); | |
36 | |
37 ON_CALL(voice_engine_, audio_transport()) | |
38 .WillByDefault(testing::Return(&audio_transport_)); | |
39 | |
40 config_.voice_engine = &voice_engine_; | |
41 config_.audio_mixer = audio_mixer_; | |
42 } | |
43 | |
44 rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; } | |
45 | |
46 MockAudioTransport& original_audio_transport() { return audio_transport_; } | |
47 | |
48 AudioState::Config& config() { return config_; } | |
49 MockVoiceEngine& voice_engine() { return voice_engine_; } | |
50 | |
the sun
2016/11/18 16:30:17
private:
aleloi
2016/11/21 11:59:11
Done.
| |
51 testing::StrictMock<MockVoiceEngine> voice_engine_; | |
52 MockAudioTransport audio_transport_; | |
53 rtc::scoped_refptr<AudioMixer> audio_mixer_; | |
54 AudioState::Config config_; | |
55 }; | |
56 | |
57 class FakeAudioSource : public AudioMixer::Source { | |
58 public: | |
59 // TODO(aleloi): Valid overrides commented out, because the gmock | |
60 // methods don't use any override declarations, and we want to avoid | |
61 // warnings from -Winconsistent-missing-override. See | |
62 // http://crbug.com/428099. | |
63 int Ssrc() const /*override*/ { return 0; } | |
64 | |
65 int PreferredSampleRate() const /*override*/ { return kSampleRate; } | |
66 | |
67 MOCK_METHOD2(GetAudioFrameWithInfo, | |
68 AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); | |
69 }; | |
70 } // namespace | |
71 | |
72 // Test that RecordedDataIsAvailable calls get to the original transport. | |
73 TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { | |
74 ConfigHelper helper; | |
75 | |
76 EXPECT_CALL(helper.voice_engine(), audio_device_module()).Times(2); | |
77 auto device = static_cast<MockAudioDeviceModule*>( | |
78 helper.voice_engine().audio_device_module()); | |
79 | |
80 // Get a local pointer to the most recent transport connected to the | |
81 // Audio Device. | |
82 AudioTransport* audio_transport_proxy = nullptr; | |
83 ON_CALL(*device, RegisterAudioCallback(testing::_)) | |
84 .WillByDefault( | |
85 testing::Invoke([&audio_transport_proxy](AudioTransport* transport) { | |
86 audio_transport_proxy = transport; | |
87 return 0; | |
88 })); | |
89 | |
90 rtc::scoped_refptr<AudioState> audio_state = | |
91 AudioState::Create(helper.config()); | |
92 | |
93 // Setup completed. Ensure call of original transport is forwarded to new. | |
94 uint32_t new_mic_level; | |
95 EXPECT_CALL( | |
96 helper.original_audio_transport(), | |
97 RecordedDataIsAvailable(nullptr, kSampleRate / 100, kBytesPerSample, | |
98 kNumberOfChannels, kSampleRate, 0, 0, 0, false, | |
99 testing::Ref(new_mic_level))); | |
100 | |
101 audio_transport_proxy->RecordedDataIsAvailable( | |
102 nullptr, kSampleRate / 100, kBytesPerSample, kNumberOfChannels, | |
103 kSampleRate, 0, 0, 0, false, new_mic_level); | |
104 } | |
105 | |
106 TEST(AudioStateAudioPathTest, | |
107 QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { | |
108 ConfigHelper helper; | |
109 | |
110 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
| |
111 auto device = static_cast<MockAudioDeviceModule*>( | |
112 helper.voice_engine().audio_device_module()); | |
113 | |
114 AudioTransport* audio_transport_proxy = nullptr; | |
115 ON_CALL(*device, RegisterAudioCallback(testing::_)) | |
116 .WillByDefault( | |
117 testing::Invoke([&audio_transport_proxy](AudioTransport* transport) { | |
118 audio_transport_proxy = transport; | |
119 return 0; | |
120 })); | |
121 | |
122 rtc::scoped_refptr<AudioState> audio_state = | |
123 AudioState::Create(helper.config()); | |
124 | |
125 FakeAudioSource fake_source; | |
126 | |
127 helper.mixer()->AddSource(&fake_source); | |
128 | |
129 EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_)) | |
130 .WillOnce( | |
131 testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) { | |
132 audio_frame->sample_rate_hz_ = sample_rate_hz; | |
133 audio_frame->samples_per_channel_ = sample_rate_hz / 100; | |
134 audio_frame->num_channels_ = kNumberOfChannels; | |
135 return AudioMixer::Source::AudioFrameInfo::kNormal; | |
136 })); | |
137 | |
138 int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels]; | |
139 size_t n_samples_out; | |
140 int64_t elapsed_time_ms; | |
141 int64_t ntp_time_ms; | |
142 audio_transport_proxy->NeedMorePlayData( | |
143 kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, | |
144 audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); | |
145 } | |
146 } // namespace test | |
147 } // namespace webrtc | |
OLD | NEW |