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

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine_unittest.cc

Issue 2961723004: Allow an external audio processing module to be used in WebRTC (Closed)
Patch Set: Moved creation of APMs from CreateVoiceEngines Created 3 years, 5 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2008 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 "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 13 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
14 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" 14 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
15 #include "webrtc/base/arraysize.h" 15 #include "webrtc/base/arraysize.h"
16 #include "webrtc/base/byteorder.h" 16 #include "webrtc/base/byteorder.h"
17 #include "webrtc/base/safe_conversions.h" 17 #include "webrtc/base/safe_conversions.h"
18 #include "webrtc/base/scoped_ref_ptr.h"
18 #include "webrtc/call/call.h" 19 #include "webrtc/call/call.h"
19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
20 #include "webrtc/media/base/fakemediaengine.h" 21 #include "webrtc/media/base/fakemediaengine.h"
21 #include "webrtc/media/base/fakenetworkinterface.h" 22 #include "webrtc/media/base/fakenetworkinterface.h"
22 #include "webrtc/media/base/fakertp.h" 23 #include "webrtc/media/base/fakertp.h"
23 #include "webrtc/media/base/mediaconstants.h" 24 #include "webrtc/media/base/mediaconstants.h"
24 #include "webrtc/media/engine/fakewebrtccall.h" 25 #include "webrtc/media/engine/fakewebrtccall.h"
25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" 26 #include "webrtc/media/engine/fakewebrtcvoiceengine.h"
26 #include "webrtc/media/engine/webrtcvoiceengine.h" 27 #include "webrtc/media/engine/webrtcvoiceengine.h"
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" 28 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 115 EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false));
115 EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); 116 EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false));
116 EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0)); 117 EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0));
117 } 118 }
118 } // namespace 119 } // namespace
119 120
120 // Tests that our stub library "works". 121 // Tests that our stub library "works".
121 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { 122 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
122 StrictMock<webrtc::test::MockAudioDeviceModule> adm; 123 StrictMock<webrtc::test::MockAudioDeviceModule> adm;
123 AdmSetupExpectations(&adm); 124 AdmSetupExpectations(&adm);
124 StrictMock<webrtc::test::MockAudioProcessing> apm; 125 rtc::scoped_refptr<StrictMock<webrtc::test::MockAudioProcessing>> apm =
125 EXPECT_CALL(apm, ApplyConfig(testing::_)); 126 new rtc::RefCountedObject<
126 EXPECT_CALL(apm, SetExtraOptions(testing::_)); 127 StrictMock<webrtc::test::MockAudioProcessing>>();
127 EXPECT_CALL(apm, Initialize()).WillOnce(Return(0)); 128 EXPECT_CALL(*apm, ApplyConfig(testing::_));
128 EXPECT_CALL(apm, DetachAecDump()); 129 EXPECT_CALL(*apm, SetExtraOptions(testing::_));
130 EXPECT_CALL(*apm, Initialize()).WillOnce(Return(0));
131 EXPECT_CALL(*apm, DetachAecDump());
129 StrictMock<MockTransmitMixer> transmit_mixer; 132 StrictMock<MockTransmitMixer> transmit_mixer;
130 EXPECT_CALL(transmit_mixer, EnableStereoChannelSwapping(false)); 133 EXPECT_CALL(transmit_mixer, EnableStereoChannelSwapping(false));
131 cricket::FakeWebRtcVoiceEngine voe(&apm, &transmit_mixer); 134 cricket::FakeWebRtcVoiceEngine voe(&transmit_mixer);
132 EXPECT_FALSE(voe.IsInited()); 135 EXPECT_FALSE(voe.IsInited());
133 { 136 {
134 cricket::WebRtcVoiceEngine engine( 137 cricket::WebRtcVoiceEngine engine(
135 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 138 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
136 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, 139 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, apm,
137 new FakeVoEWrapper(&voe)); 140 new FakeVoEWrapper(&voe));
138 engine.Init(); 141 engine.Init();
139 EXPECT_TRUE(voe.IsInited()); 142 EXPECT_TRUE(voe.IsInited());
140 } 143 }
141 EXPECT_FALSE(voe.IsInited()); 144 EXPECT_FALSE(voe.IsInited());
142 } 145 }
143 146
144 class FakeAudioSink : public webrtc::AudioSinkInterface { 147 class FakeAudioSink : public webrtc::AudioSinkInterface {
145 public: 148 public:
146 void OnData(const Data& audio) override {} 149 void OnData(const Data& audio) override {}
147 }; 150 };
148 151
149 class FakeAudioSource : public cricket::AudioSource { 152 class FakeAudioSource : public cricket::AudioSource {
150 void SetSink(Sink* sink) override {} 153 void SetSink(Sink* sink) override {}
151 }; 154 };
152 155
153 class WebRtcVoiceEngineTestFake : public testing::Test { 156 class WebRtcVoiceEngineTestFake : public testing::Test {
154 public: 157 public:
155 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} 158 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {}
156 159
157 explicit WebRtcVoiceEngineTestFake(const char* field_trials) 160 explicit WebRtcVoiceEngineTestFake(const char* field_trials)
158 : apm_gc_(*apm_.gain_control()), apm_ec_(*apm_.echo_cancellation()), 161 : apm_(new rtc::RefCountedObject<
159 apm_ns_(*apm_.noise_suppression()), apm_vd_(*apm_.voice_detection()), 162 StrictMock<webrtc::test::MockAudioProcessing>>()),
160 call_(webrtc::Call::Config(&event_log_)), voe_(&apm_, &transmit_mixer_), 163 apm_gc_(*apm_->gain_control()),
164 apm_ec_(*apm_->echo_cancellation()),
165 apm_ns_(*apm_->noise_suppression()),
166 apm_vd_(*apm_->voice_detection()),
167 call_(webrtc::Call::Config(&event_log_)),
168 voe_(&transmit_mixer_),
161 override_field_trials_(field_trials) { 169 override_field_trials_(field_trials) {
162 // AudioDeviceModule. 170 // AudioDeviceModule.
163 AdmSetupExpectations(&adm_); 171 AdmSetupExpectations(&adm_);
164 // AudioProcessing. 172 // AudioProcessing.
165 EXPECT_CALL(apm_, ApplyConfig(testing::_)); 173 EXPECT_CALL(*apm_, ApplyConfig(testing::_));
166 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); 174 EXPECT_CALL(*apm_, SetExtraOptions(testing::_));
167 EXPECT_CALL(apm_, Initialize()).WillOnce(Return(0)); 175 EXPECT_CALL(*apm_, Initialize()).WillOnce(Return(0));
168 EXPECT_CALL(apm_, DetachAecDump()); 176 EXPECT_CALL(*apm_, DetachAecDump());
169 // Default Options. 177 // Default Options.
170 EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0)); 178 EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0));
171 EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0)); 179 EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0));
172 EXPECT_CALL(apm_gc_, Enable(true)).WillOnce(Return(0)); 180 EXPECT_CALL(apm_gc_, Enable(true)).WillOnce(Return(0));
173 EXPECT_CALL(apm_ns_, Enable(true)).WillOnce(Return(0)); 181 EXPECT_CALL(apm_ns_, Enable(true)).WillOnce(Return(0));
174 EXPECT_CALL(apm_vd_, Enable(true)).WillOnce(Return(0)); 182 EXPECT_CALL(apm_vd_, Enable(true)).WillOnce(Return(0));
175 EXPECT_CALL(transmit_mixer_, EnableStereoChannelSwapping(false)); 183 EXPECT_CALL(transmit_mixer_, EnableStereoChannelSwapping(false));
176 // Init does not overwrite default AGC config. 184 // Init does not overwrite default AGC config.
177 EXPECT_CALL(apm_gc_, target_level_dbfs()).WillOnce(Return(1)); 185 EXPECT_CALL(apm_gc_, target_level_dbfs()).WillOnce(Return(1));
178 EXPECT_CALL(apm_gc_, compression_gain_db()).WillRepeatedly(Return(5)); 186 EXPECT_CALL(apm_gc_, compression_gain_db()).WillRepeatedly(Return(5));
179 EXPECT_CALL(apm_gc_, is_limiter_enabled()).WillRepeatedly(Return(true)); 187 EXPECT_CALL(apm_gc_, is_limiter_enabled()).WillRepeatedly(Return(true));
180 EXPECT_CALL(apm_gc_, set_target_level_dbfs(1)).WillOnce(Return(0)); 188 EXPECT_CALL(apm_gc_, set_target_level_dbfs(1)).WillOnce(Return(0));
181 EXPECT_CALL(apm_gc_, set_compression_gain_db(5)).WillRepeatedly(Return(0)); 189 EXPECT_CALL(apm_gc_, set_compression_gain_db(5)).WillRepeatedly(Return(0));
182 EXPECT_CALL(apm_gc_, enable_limiter(true)).WillRepeatedly(Return(0)); 190 EXPECT_CALL(apm_gc_, enable_limiter(true)).WillRepeatedly(Return(0));
183 // TODO(kwiberg): We should use mock factories here, but a bunch of 191 // TODO(kwiberg): We should use mock factories here, but a bunch of
184 // the tests here probe the specific set of codecs provided by the builtin 192 // the tests here probe the specific set of codecs provided by the builtin
185 // factories. Those tests should probably be moved elsewhere. 193 // factories. Those tests should probably be moved elsewhere.
186 auto encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); 194 auto encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
187 auto decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); 195 auto decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
188 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, encoder_factory, 196 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, encoder_factory,
189 decoder_factory, nullptr, 197 decoder_factory, nullptr, apm_,
190 new FakeVoEWrapper(&voe_))); 198 new FakeVoEWrapper(&voe_)));
191 engine_->Init(); 199 engine_->Init();
192 send_parameters_.codecs.push_back(kPcmuCodec); 200 send_parameters_.codecs.push_back(kPcmuCodec);
193 recv_parameters_.codecs.push_back(kPcmuCodec); 201 recv_parameters_.codecs.push_back(kPcmuCodec);
194 // Default Options. 202 // Default Options.
195 EXPECT_TRUE(IsHighPassFilterEnabled()); 203 EXPECT_TRUE(IsHighPassFilterEnabled());
196 } 204 }
197 205
198 bool SetupChannel() { 206 bool SetupChannel() {
199 EXPECT_CALL(apm_, ApplyConfig(testing::_)); 207 EXPECT_CALL(*apm_, ApplyConfig(testing::_));
200 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); 208 EXPECT_CALL(*apm_, SetExtraOptions(testing::_));
201 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), 209 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(),
202 cricket::AudioOptions()); 210 cricket::AudioOptions());
203 return (channel_ != nullptr); 211 return (channel_ != nullptr);
204 } 212 }
205 213
206 bool SetupRecvStream() { 214 bool SetupRecvStream() {
207 if (!SetupChannel()) { 215 if (!SetupChannel()) {
208 return false; 216 return false;
209 } 217 }
210 return AddRecvStream(kSsrcX); 218 return AddRecvStream(kSsrcX);
211 } 219 }
212 220
213 bool SetupSendStream() { 221 bool SetupSendStream() {
214 if (!SetupChannel()) { 222 if (!SetupChannel()) {
215 return false; 223 return false;
216 } 224 }
217 if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcX))) { 225 if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcX))) {
218 return false; 226 return false;
219 } 227 }
220 EXPECT_CALL(apm_, set_output_will_be_muted(false)); 228 EXPECT_CALL(*apm_, set_output_will_be_muted(false));
221 return channel_->SetAudioSend(kSsrcX, true, nullptr, &fake_source_); 229 return channel_->SetAudioSend(kSsrcX, true, nullptr, &fake_source_);
222 } 230 }
223 231
224 bool AddRecvStream(uint32_t ssrc) { 232 bool AddRecvStream(uint32_t ssrc) {
225 EXPECT_TRUE(channel_); 233 EXPECT_TRUE(channel_);
226 return channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(ssrc)); 234 return channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(ssrc));
227 } 235 }
228 236
229 void SetupForMultiSendStream() { 237 void SetupForMultiSendStream() {
230 EXPECT_TRUE(SetupSendStream()); 238 EXPECT_TRUE(SetupSendStream());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { 271 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) {
264 return GetRecvStream(ssrc).GetConfig(); 272 return GetRecvStream(ssrc).GetConfig();
265 } 273 }
266 274
267 void SetSend(bool enable) { 275 void SetSend(bool enable) {
268 ASSERT_TRUE(channel_); 276 ASSERT_TRUE(channel_);
269 if (enable) { 277 if (enable) {
270 EXPECT_CALL(adm_, RecordingIsInitialized()).WillOnce(Return(false)); 278 EXPECT_CALL(adm_, RecordingIsInitialized()).WillOnce(Return(false));
271 EXPECT_CALL(adm_, Recording()).WillOnce(Return(false)); 279 EXPECT_CALL(adm_, Recording()).WillOnce(Return(false));
272 EXPECT_CALL(adm_, InitRecording()).WillOnce(Return(0)); 280 EXPECT_CALL(adm_, InitRecording()).WillOnce(Return(0));
273 EXPECT_CALL(apm_, ApplyConfig(testing::_)); 281 EXPECT_CALL(*apm_, ApplyConfig(testing::_));
274 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); 282 EXPECT_CALL(*apm_, SetExtraOptions(testing::_));
275 } 283 }
276 channel_->SetSend(enable); 284 channel_->SetSend(enable);
277 } 285 }
278 286
279 void SetSendParameters(const cricket::AudioSendParameters& params) { 287 void SetSendParameters(const cricket::AudioSendParameters& params) {
280 EXPECT_CALL(apm_, ApplyConfig(testing::_)); 288 EXPECT_CALL(*apm_, ApplyConfig(testing::_));
281 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); 289 EXPECT_CALL(*apm_, SetExtraOptions(testing::_));
282 ASSERT_TRUE(channel_); 290 ASSERT_TRUE(channel_);
283 EXPECT_TRUE(channel_->SetSendParameters(params)); 291 EXPECT_TRUE(channel_->SetSendParameters(params));
284 } 292 }
285 293
286 void SetAudioSend(uint32_t ssrc, bool enable, cricket::AudioSource* source, 294 void SetAudioSend(uint32_t ssrc, bool enable, cricket::AudioSource* source,
287 const cricket::AudioOptions* options = nullptr) { 295 const cricket::AudioOptions* options = nullptr) {
288 EXPECT_CALL(apm_, set_output_will_be_muted(!enable)); 296 EXPECT_CALL(*apm_, set_output_will_be_muted(!enable));
289 ASSERT_TRUE(channel_); 297 ASSERT_TRUE(channel_);
290 if (enable && options) { 298 if (enable && options) {
291 EXPECT_CALL(apm_, ApplyConfig(testing::_)); 299 EXPECT_CALL(*apm_, ApplyConfig(testing::_));
292 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); 300 EXPECT_CALL(*apm_, SetExtraOptions(testing::_));
293 } 301 }
294 EXPECT_TRUE(channel_->SetAudioSend(ssrc, enable, options, source)); 302 EXPECT_TRUE(channel_->SetAudioSend(ssrc, enable, options, source));
295 } 303 }
296 304
297 void TestInsertDtmf(uint32_t ssrc, bool caller, 305 void TestInsertDtmf(uint32_t ssrc, bool caller,
298 const cricket::AudioCodec& codec) { 306 const cricket::AudioCodec& codec) {
299 EXPECT_TRUE(SetupChannel()); 307 EXPECT_TRUE(SetupChannel());
300 if (caller) { 308 if (caller) {
301 // If this is a caller, local description will be applied and add the 309 // If this is a caller, local description will be applied and add the
302 // send stream. 310 // send stream.
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 codec.ToCodecParameters()); 659 codec.ToCodecParameters());
652 } 660 }
653 } 661 }
654 662
655 bool IsHighPassFilterEnabled() { 663 bool IsHighPassFilterEnabled() {
656 return engine_->GetApmConfigForTest().high_pass_filter.enabled; 664 return engine_->GetApmConfigForTest().high_pass_filter.enabled;
657 } 665 }
658 666
659 protected: 667 protected:
660 StrictMock<webrtc::test::MockAudioDeviceModule> adm_; 668 StrictMock<webrtc::test::MockAudioDeviceModule> adm_;
661 StrictMock<webrtc::test::MockAudioProcessing> apm_; 669 rtc::scoped_refptr<StrictMock<webrtc::test::MockAudioProcessing>> apm_;
662 webrtc::test::MockGainControl& apm_gc_; 670 webrtc::test::MockGainControl& apm_gc_;
663 webrtc::test::MockEchoCancellation& apm_ec_; 671 webrtc::test::MockEchoCancellation& apm_ec_;
664 webrtc::test::MockNoiseSuppression& apm_ns_; 672 webrtc::test::MockNoiseSuppression& apm_ns_;
665 webrtc::test::MockVoiceDetection& apm_vd_; 673 webrtc::test::MockVoiceDetection& apm_vd_;
666 StrictMock<MockTransmitMixer> transmit_mixer_; 674 StrictMock<MockTransmitMixer> transmit_mixer_;
667 webrtc::RtcEventLogNullImpl event_log_; 675 webrtc::RtcEventLogNullImpl event_log_;
668 cricket::FakeCall call_; 676 cricket::FakeCall call_;
669 cricket::FakeWebRtcVoiceEngine voe_; 677 cricket::FakeWebRtcVoiceEngine voe_;
670 std::unique_ptr<cricket::WebRtcVoiceEngine> engine_; 678 std::unique_ptr<cricket::WebRtcVoiceEngine> engine_;
671 cricket::VoiceMediaChannel* channel_ = nullptr; 679 cricket::VoiceMediaChannel* channel_ = nullptr;
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 EXPECT_CALL(adm_, 2795 EXPECT_CALL(adm_,
2788 BuiltInAECIsAvailable()).Times(8).WillRepeatedly(Return(false)); 2796 BuiltInAECIsAvailable()).Times(8).WillRepeatedly(Return(false));
2789 EXPECT_CALL(adm_, 2797 EXPECT_CALL(adm_,
2790 BuiltInAGCIsAvailable()).Times(8).WillRepeatedly(Return(false)); 2798 BuiltInAGCIsAvailable()).Times(8).WillRepeatedly(Return(false));
2791 EXPECT_CALL(adm_, 2799 EXPECT_CALL(adm_,
2792 BuiltInNSIsAvailable()).Times(8).WillRepeatedly(Return(false)); 2800 BuiltInNSIsAvailable()).Times(8).WillRepeatedly(Return(false));
2793 EXPECT_CALL(adm_, 2801 EXPECT_CALL(adm_,
2794 RecordingIsInitialized()).Times(2).WillRepeatedly(Return(false)); 2802 RecordingIsInitialized()).Times(2).WillRepeatedly(Return(false));
2795 EXPECT_CALL(adm_, Recording()).Times(2).WillRepeatedly(Return(false)); 2803 EXPECT_CALL(adm_, Recording()).Times(2).WillRepeatedly(Return(false));
2796 EXPECT_CALL(adm_, InitRecording()).Times(2).WillRepeatedly(Return(0)); 2804 EXPECT_CALL(adm_, InitRecording()).Times(2).WillRepeatedly(Return(0));
2797 EXPECT_CALL(apm_, ApplyConfig(testing::_)).Times(10); 2805 EXPECT_CALL(*apm_, ApplyConfig(testing::_)).Times(10);
2798 EXPECT_CALL(apm_, SetExtraOptions(testing::_)).Times(10); 2806 EXPECT_CALL(*apm_, SetExtraOptions(testing::_)).Times(10);
2799 2807
2800 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel1( 2808 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel1(
2801 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_->CreateChannel( 2809 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_->CreateChannel(
2802 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2810 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2803 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel2( 2811 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel2(
2804 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_->CreateChannel( 2812 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_->CreateChannel(
2805 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2813 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2806 2814
2807 // Have to add a stream to make SetSend work. 2815 // Have to add a stream to make SetSend work.
2808 cricket::StreamParams stream1; 2816 cricket::StreamParams stream1;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 EXPECT_EQ(expected_options, channel2->options()); 2906 EXPECT_EQ(expected_options, channel2->options());
2899 } 2907 }
2900 2908
2901 // This test verifies DSCP settings are properly applied on voice media channel. 2909 // This test verifies DSCP settings are properly applied on voice media channel.
2902 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { 2910 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
2903 EXPECT_TRUE(SetupSendStream()); 2911 EXPECT_TRUE(SetupSendStream());
2904 cricket::FakeNetworkInterface network_interface; 2912 cricket::FakeNetworkInterface network_interface;
2905 cricket::MediaConfig config; 2913 cricket::MediaConfig config;
2906 std::unique_ptr<cricket::VoiceMediaChannel> channel; 2914 std::unique_ptr<cricket::VoiceMediaChannel> channel;
2907 2915
2908 EXPECT_CALL(apm_, ApplyConfig(testing::_)).Times(3); 2916 EXPECT_CALL(*apm_, ApplyConfig(testing::_)).Times(3);
2909 EXPECT_CALL(apm_, SetExtraOptions(testing::_)).Times(3); 2917 EXPECT_CALL(*apm_, SetExtraOptions(testing::_)).Times(3);
2910 2918
2911 channel.reset( 2919 channel.reset(
2912 engine_->CreateChannel(&call_, config, cricket::AudioOptions())); 2920 engine_->CreateChannel(&call_, config, cricket::AudioOptions()));
2913 channel->SetInterface(&network_interface); 2921 channel->SetInterface(&network_interface);
2914 // Default value when DSCP is disabled should be DSCP_DEFAULT. 2922 // Default value when DSCP is disabled should be DSCP_DEFAULT.
2915 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp()); 2923 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp());
2916 2924
2917 config.enable_dscp = true; 2925 config.enable_dscp = true;
2918 channel.reset( 2926 channel.reset(
2919 engine_->CreateChannel(&call_, config, cricket::AudioOptions())); 2927 engine_->CreateChannel(&call_, config, cricket::AudioOptions()));
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, 12)); 3263 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, 12));
3256 channel_->SetRecvParameters(parameters); 3264 channel_->SetRecvParameters(parameters);
3257 3265
3258 EXPECT_TRUE(GetRecvStream(kSsrcX).started()); 3266 EXPECT_TRUE(GetRecvStream(kSsrcX).started());
3259 } 3267 }
3260 3268
3261 // Tests that the library initializes and shuts down properly. 3269 // Tests that the library initializes and shuts down properly.
3262 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3270 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3263 // If the VoiceEngine wants to gather available codecs early, that's fine but 3271 // If the VoiceEngine wants to gather available codecs early, that's fine but
3264 // we never want it to create a decoder at this stage. 3272 // we never want it to create a decoder at this stage.
3273 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3274 webrtc::AudioProcessing::Create();
3265 cricket::WebRtcVoiceEngine engine( 3275 cricket::WebRtcVoiceEngine engine(
3266 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3276 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3267 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3277 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, apm);
3268 engine.Init(); 3278 engine.Init();
3269 webrtc::RtcEventLogNullImpl event_log; 3279 webrtc::RtcEventLogNullImpl event_log;
3270 std::unique_ptr<webrtc::Call> call( 3280 std::unique_ptr<webrtc::Call> call(
3271 webrtc::Call::Create(webrtc::Call::Config(&event_log))); 3281 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3272 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3282 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3273 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3283 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3274 EXPECT_TRUE(channel != nullptr); 3284 EXPECT_TRUE(channel != nullptr);
3275 delete channel; 3285 delete channel;
3276 } 3286 }
3277 3287
3278 // Tests that reference counting on the external ADM is correct. 3288 // Tests that reference counting on the external ADM is correct.
3279 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { 3289 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) {
3280 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; 3290 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm;
3281 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); 3291 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0));
3282 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); 3292 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0));
3283 // Return 100ms just in case this function gets called. If we don't, 3293 // Return 100ms just in case this function gets called. If we don't,
3284 // we could enter a tight loop since the mock would return 0. 3294 // we could enter a tight loop since the mock would return 0.
3285 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100)); 3295 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100));
3286 { 3296 {
3297 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3298 webrtc::AudioProcessing::Create();
3287 cricket::WebRtcVoiceEngine engine( 3299 cricket::WebRtcVoiceEngine engine(
3288 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3300 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3289 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3301 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, apm);
3290 engine.Init(); 3302 engine.Init();
3291 webrtc::RtcEventLogNullImpl event_log; 3303 webrtc::RtcEventLogNullImpl event_log;
3292 std::unique_ptr<webrtc::Call> call( 3304 std::unique_ptr<webrtc::Call> call(
3293 webrtc::Call::Create(webrtc::Call::Config(&event_log))); 3305 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3294 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3306 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3295 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3307 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3296 EXPECT_TRUE(channel != nullptr); 3308 EXPECT_TRUE(channel != nullptr);
3297 delete channel; 3309 delete channel;
3298 } 3310 }
3299 } 3311 }
3300 3312
3301 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. 3313 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3302 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) { 3314 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) {
3303 // TODO(ossu): Why are the payload types of codecs with non-static payload 3315 // TODO(ossu): Why are the payload types of codecs with non-static payload
3304 // type assignments checked here? It shouldn't really matter. 3316 // type assignments checked here? It shouldn't really matter.
3317 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3318 webrtc::AudioProcessing::Create();
3305 cricket::WebRtcVoiceEngine engine( 3319 cricket::WebRtcVoiceEngine engine(
3306 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3320 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3307 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3321 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, apm);
3308 engine.Init(); 3322 engine.Init();
3309 for (const cricket::AudioCodec& codec : engine.send_codecs()) { 3323 for (const cricket::AudioCodec& codec : engine.send_codecs()) {
3310 auto is_codec = [&codec](const char* name, int clockrate = 0) { 3324 auto is_codec = [&codec](const char* name, int clockrate = 0) {
3311 return STR_CASE_CMP(codec.name.c_str(), name) == 0 && 3325 return STR_CASE_CMP(codec.name.c_str(), name) == 0 &&
3312 (clockrate == 0 || codec.clockrate == clockrate); 3326 (clockrate == 0 || codec.clockrate == clockrate);
3313 }; 3327 };
3314 if (is_codec("CN", 16000)) { 3328 if (is_codec("CN", 16000)) {
3315 EXPECT_EQ(105, codec.id); 3329 EXPECT_EQ(105, codec.id);
3316 } else if (is_codec("CN", 32000)) { 3330 } else if (is_codec("CN", 32000)) {
3317 EXPECT_EQ(106, codec.id); 3331 EXPECT_EQ(106, codec.id);
(...skipping 19 matching lines...) Expand all
3337 ASSERT_TRUE(codec.params.find("minptime") != codec.params.end()); 3351 ASSERT_TRUE(codec.params.find("minptime") != codec.params.end());
3338 EXPECT_EQ("10", codec.params.find("minptime")->second); 3352 EXPECT_EQ("10", codec.params.find("minptime")->second);
3339 ASSERT_TRUE(codec.params.find("useinbandfec") != codec.params.end()); 3353 ASSERT_TRUE(codec.params.find("useinbandfec") != codec.params.end());
3340 EXPECT_EQ("1", codec.params.find("useinbandfec")->second); 3354 EXPECT_EQ("1", codec.params.find("useinbandfec")->second);
3341 } 3355 }
3342 } 3356 }
3343 } 3357 }
3344 3358
3345 // Tests that VoE supports at least 32 channels 3359 // Tests that VoE supports at least 32 channels
3346 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3360 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3361 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3362 webrtc::AudioProcessing::Create();
3347 cricket::WebRtcVoiceEngine engine( 3363 cricket::WebRtcVoiceEngine engine(
3348 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3364 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3349 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3365 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, apm);
3350 engine.Init(); 3366 engine.Init();
3351 webrtc::RtcEventLogNullImpl event_log; 3367 webrtc::RtcEventLogNullImpl event_log;
3352 std::unique_ptr<webrtc::Call> call( 3368 std::unique_ptr<webrtc::Call> call(
3353 webrtc::Call::Create(webrtc::Call::Config(&event_log))); 3369 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3354 3370
3355 cricket::VoiceMediaChannel* channels[32]; 3371 cricket::VoiceMediaChannel* channels[32];
3356 int num_channels = 0; 3372 int num_channels = 0;
3357 while (num_channels < arraysize(channels)) { 3373 while (num_channels < arraysize(channels)) {
3358 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3374 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3359 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3375 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
(...skipping 12 matching lines...) Expand all
3372 3388
3373 // Test that we set our preferred codecs properly. 3389 // Test that we set our preferred codecs properly.
3374 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3390 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3375 // TODO(ossu): I'm not sure of the intent of this test. It's either: 3391 // TODO(ossu): I'm not sure of the intent of this test. It's either:
3376 // - Check that our builtin codecs are usable by Channel. 3392 // - Check that our builtin codecs are usable by Channel.
3377 // - The codecs provided by the engine is usable by Channel. 3393 // - The codecs provided by the engine is usable by Channel.
3378 // It does not check that the codecs in the RecvParameters are actually 3394 // It does not check that the codecs in the RecvParameters are actually
3379 // what we sent in - though it's probably reasonable to expect so, if 3395 // what we sent in - though it's probably reasonable to expect so, if
3380 // SetRecvParameters returns true. 3396 // SetRecvParameters returns true.
3381 // I think it will become clear once audio decoder injection is completed. 3397 // I think it will become clear once audio decoder injection is completed.
3398 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3399 webrtc::AudioProcessing::Create();
3382 cricket::WebRtcVoiceEngine engine( 3400 cricket::WebRtcVoiceEngine engine(
3383 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3401 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3384 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr); 3402 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, apm);
3385 engine.Init(); 3403 engine.Init();
3386 webrtc::RtcEventLogNullImpl event_log; 3404 webrtc::RtcEventLogNullImpl event_log;
3387 std::unique_ptr<webrtc::Call> call( 3405 std::unique_ptr<webrtc::Call> call(
3388 webrtc::Call::Create(webrtc::Call::Config(&event_log))); 3406 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3389 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3407 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3390 cricket::AudioOptions(), call.get()); 3408 cricket::AudioOptions(), call.get());
3391 cricket::AudioRecvParameters parameters; 3409 cricket::AudioRecvParameters parameters;
3392 parameters.codecs = engine.recv_codecs(); 3410 parameters.codecs = engine.recv_codecs();
3393 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3411 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3394 } 3412 }
(...skipping 16 matching lines...) Expand all
3411 specs.push_back( 3429 specs.push_back(
3412 webrtc::AudioCodecSpec{{"codec5", 8000, 2}, {8000, 1, 64000}}); 3430 webrtc::AudioCodecSpec{{"codec5", 8000, 2}, {8000, 1, 64000}});
3413 3431
3414 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> unused_encoder_factory = 3432 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> unused_encoder_factory =
3415 webrtc::MockAudioEncoderFactory::CreateUnusedFactory(); 3433 webrtc::MockAudioEncoderFactory::CreateUnusedFactory();
3416 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_decoder_factory = 3434 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_decoder_factory =
3417 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; 3435 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>;
3418 EXPECT_CALL(*mock_decoder_factory.get(), GetSupportedDecoders()) 3436 EXPECT_CALL(*mock_decoder_factory.get(), GetSupportedDecoders())
3419 .WillOnce(Return(specs)); 3437 .WillOnce(Return(specs));
3420 3438
3439 rtc::scoped_refptr<webrtc::AudioProcessing> apm =
3440 webrtc::AudioProcessing::Create();
3421 cricket::WebRtcVoiceEngine engine(nullptr, unused_encoder_factory, 3441 cricket::WebRtcVoiceEngine engine(nullptr, unused_encoder_factory,
3422 mock_decoder_factory, nullptr); 3442 mock_decoder_factory, nullptr, apm);
3423 engine.Init(); 3443 engine.Init();
3424 auto codecs = engine.recv_codecs(); 3444 auto codecs = engine.recv_codecs();
3425 EXPECT_EQ(11, codecs.size()); 3445 EXPECT_EQ(11, codecs.size());
3426 3446
3427 // Rather than just ASSERTing that there are enough codecs, ensure that we can 3447 // Rather than just ASSERTing that there are enough codecs, ensure that we can
3428 // check the actual values safely, to provide better test results. 3448 // check the actual values safely, to provide better test results.
3429 auto get_codec = 3449 auto get_codec =
3430 [&codecs](size_t index) -> const cricket::AudioCodec& { 3450 [&codecs](size_t index) -> const cricket::AudioCodec& {
3431 static const cricket::AudioCodec missing_codec(0, "<missing>", 0, 0, 0); 3451 static const cricket::AudioCodec missing_codec(0, "<missing>", 0, 0, 0);
3432 if (codecs.size() > index) 3452 if (codecs.size() > index)
(...skipping 29 matching lines...) Expand all
3462 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3482 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3463 const int num_specs = static_cast<int>(specs.size()); 3483 const int num_specs = static_cast<int>(specs.size());
3464 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3484 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3465 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3485 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3466 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3486 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3467 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3487 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3468 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3488 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3469 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3489 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3470 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3490 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3471 } 3491 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/modules/audio_processing/audio_processing_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698