OLD | NEW |
---|---|
(Empty) | |
1 /* | |
ossu
2016/11/21 17:07:32
As we spoke about offline, I don't think you shoul
aleloi
2016/11/22 13:23:40
Done.
| |
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(mock_voice_engine, RegisterVoiceEngineObserver(testing::_)) | |
31 .WillOnce(testing::Return(0)); | |
32 EXPECT_CALL(mock_voice_engine, DeRegisterVoiceEngineObserver()) | |
33 .WillOnce(testing::Return(0)); | |
34 EXPECT_CALL(mock_voice_engine, audio_processing()); | |
35 EXPECT_CALL(mock_voice_engine, audio_transport()); | |
36 | |
37 ON_CALL(mock_voice_engine, audio_transport()) | |
38 .WillByDefault(testing::Return(&audio_transport)); | |
39 | |
40 audio_state_config.voice_engine = &mock_voice_engine; | |
41 audio_state_config.audio_mixer = audio_mixer; | |
42 | |
43 EXPECT_CALL(voice_engine(), audio_device_module()).Times(2); | |
44 auto device = static_cast<MockAudioDeviceModule*>( | |
45 voice_engine().audio_device_module()); | |
46 | |
47 // Populate the audio transport proxy pointer to the most recent | |
48 // transport connected to the Audio Device. | |
49 ON_CALL(*device, RegisterAudioCallback(testing::_)) | |
50 .WillByDefault(testing::Invoke([this](AudioTransport* transport) { | |
51 registered_audio_transport = transport; | |
52 return 0; | |
53 })); | |
54 } | |
55 | |
56 rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer; } | |
57 | |
58 MockAudioTransport& original_audio_transport() { return audio_transport; } | |
59 AudioTransport* audio_transport_proxy() { return registered_audio_transport; } | |
60 | |
61 AudioState::Config& config() { return audio_state_config; } | |
62 MockVoiceEngine& voice_engine() { return mock_voice_engine; } | |
the sun
2016/11/22 08:47:45
nit: this doesn't strictly need to be public...
| |
63 | |
64 private: | |
65 testing::StrictMock<MockVoiceEngine> mock_voice_engine; | |
66 MockAudioTransport audio_transport; | |
67 rtc::scoped_refptr<AudioMixer> audio_mixer; | |
68 AudioTransport* registered_audio_transport = nullptr; | |
69 AudioState::Config audio_state_config; | |
70 }; | |
71 | |
72 class FakeAudioSource : public AudioMixer::Source { | |
73 public: | |
74 // TODO(aleloi): Valid overrides commented out, because the gmock | |
75 // methods don't use any override declarations, and we want to avoid | |
76 // warnings from -Winconsistent-missing-override. See | |
77 // http://crbug.com/428099. | |
78 int Ssrc() const /*override*/ { return 0; } | |
79 | |
80 int PreferredSampleRate() const /*override*/ { return kSampleRate; } | |
81 | |
82 MOCK_METHOD2(GetAudioFrameWithInfo, | |
83 AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); | |
84 }; | |
85 } // namespace | |
86 | |
87 // Test that RecordedDataIsAvailable calls get to the original transport. | |
88 TEST(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { | |
89 ConfigHelper helper; | |
90 | |
91 rtc::scoped_refptr<AudioState> audio_state = | |
92 AudioState::Create(helper.config()); | |
93 | |
94 // Setup completed. Ensure call of original transport is forwarded to new. | |
95 uint32_t new_mic_level; | |
96 EXPECT_CALL( | |
97 helper.original_audio_transport(), | |
98 RecordedDataIsAvailable(nullptr, kSampleRate / 100, kBytesPerSample, | |
99 kNumberOfChannels, kSampleRate, 0, 0, 0, false, | |
100 testing::Ref(new_mic_level))); | |
101 | |
102 helper.audio_transport_proxy()->RecordedDataIsAvailable( | |
103 nullptr, kSampleRate / 100, kBytesPerSample, kNumberOfChannels, | |
104 kSampleRate, 0, 0, 0, false, new_mic_level); | |
105 } | |
106 | |
107 TEST(AudioStateAudioPathTest, | |
108 QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { | |
109 ConfigHelper helper; | |
110 | |
111 rtc::scoped_refptr<AudioState> audio_state = | |
112 AudioState::Create(helper.config()); | |
113 | |
114 FakeAudioSource fake_source; | |
115 | |
116 helper.mixer()->AddSource(&fake_source); | |
117 | |
118 EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_)) | |
119 .WillOnce( | |
120 testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) { | |
121 audio_frame->sample_rate_hz_ = sample_rate_hz; | |
122 audio_frame->samples_per_channel_ = sample_rate_hz / 100; | |
123 audio_frame->num_channels_ = kNumberOfChannels; | |
124 return AudioMixer::Source::AudioFrameInfo::kNormal; | |
125 })); | |
126 | |
127 int16_t audio_buffer[kSampleRate / 100 * kNumberOfChannels]; | |
128 size_t n_samples_out; | |
129 int64_t elapsed_time_ms; | |
130 int64_t ntp_time_ms; | |
131 helper.audio_transport_proxy()->NeedMorePlayData( | |
132 kSampleRate / 100, kBytesPerSample, kNumberOfChannels, kSampleRate, | |
133 audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms); | |
134 } | |
135 } // namespace test | |
136 } // namespace webrtc | |
OLD | NEW |