blob: 61773043725e69481d66fdeadd6fbe4ad7186bc7 [file] [log] [blame]
Fredrik Solenberg0ccae132015-11-03 10:15:49 +01001/*
2 * Copyright (c) 2015 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#ifndef WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_
12#define WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_
13
kwibergb7f89d62016-02-17 10:04:18 -080014#include <memory>
15
aleloidd310712016-11-17 06:28:59 -080016#include "webrtc/modules/audio_device/include/mock_audio_device.h"
17#include "webrtc/modules/audio_device/include/mock_audio_transport.h"
18#include "webrtc/modules/audio_processing/include/mock_audio_processing.h"
kwiberg77eab702016-09-28 17:42:01 -070019#include "webrtc/test/gmock.h"
solenberg13725082015-11-25 08:16:52 -080020#include "webrtc/test/mock_voe_channel_proxy.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010021#include "webrtc/voice_engine/voice_engine_impl.h"
22
23namespace webrtc {
24namespace test {
25
26// NOTE: This class inherits from VoiceEngineImpl so that its clients will be
27// able to get the various interfaces as usual, via T::GetInterface().
solenberg3a941542015-11-16 07:34:50 -080028class MockVoiceEngine : public VoiceEngineImpl {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010029 public:
nisseef8b61e2016-04-29 06:09:15 -070030 // TODO(nisse): Valid overrides commented out, because the gmock
31 // methods don't use any override declarations, and we want to avoid
32 // warnings from -Winconsistent-missing-override. See
33 // http://crbug.com/428099.
ossu29b1a8d2016-06-13 07:34:51 -070034 MockVoiceEngine(
35 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr)
solenberg88499ec2016-09-07 07:34:41 -070036 : decoder_factory_(decoder_factory) {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010037 // Increase ref count so this object isn't automatically deleted whenever
38 // interfaces are Release():d.
39 ++_ref_count;
solenberg13725082015-11-25 08:16:52 -080040 // We add this default behavior to make the mock easier to use in tests. It
41 // will create a NiceMock of a voe::ChannelProxy.
solenberg7602aab2016-11-14 11:30:07 -080042 // TODO(ossu): As long as AudioReceiveStream is implemented as a wrapper
ossu29b1a8d2016-06-13 07:34:51 -070043 // around Channel, we need to make sure ChannelProxy returns the same
44 // decoder factory as the one passed in when creating an AudioReceiveStream.
solenberg13725082015-11-25 08:16:52 -080045 ON_CALL(*this, ChannelProxyFactory(testing::_))
ossu29b1a8d2016-06-13 07:34:51 -070046 .WillByDefault(testing::Invoke([this](int channel_id) {
47 auto* proxy =
48 new testing::NiceMock<webrtc::test::MockVoEChannelProxy>();
49 EXPECT_CALL(*proxy, GetAudioDecoderFactory())
50 .WillRepeatedly(testing::ReturnRef(decoder_factory_));
51 return proxy;
52 }));
aleloidd310712016-11-17 06:28:59 -080053
54 ON_CALL(*this, audio_device_module())
55 .WillByDefault(testing::Return(&mock_audio_device_));
56 ON_CALL(*this, audio_processing())
57 .WillByDefault(testing::Return(&mock_audio_processing_));
58 ON_CALL(*this, audio_transport())
59 .WillByDefault(testing::Return(&mock_audio_transport_));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010060 }
solenberg7602aab2016-11-14 11:30:07 -080061 virtual ~MockVoiceEngine() /* override */ {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010062 // Decrease ref count before base class d-tor is called; otherwise it will
63 // trigger an assertion.
64 --_ref_count;
65 }
solenberg13725082015-11-25 08:16:52 -080066 // Allows injecting a ChannelProxy factory.
67 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id));
68
69 // VoiceEngineImpl
solenberg7602aab2016-11-14 11:30:07 -080070 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy(
nisseef8b61e2016-04-29 06:09:15 -070071 int channel_id) /* override */ {
kwibergb7f89d62016-02-17 10:04:18 -080072 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id));
solenberg13725082015-11-25 08:16:52 -080073 }
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010074
75 // VoEAudioProcessing
76 MOCK_METHOD2(SetNsStatus, int(bool enable, NsModes mode));
77 MOCK_METHOD2(GetNsStatus, int(bool& enabled, NsModes& mode));
78 MOCK_METHOD2(SetAgcStatus, int(bool enable, AgcModes mode));
79 MOCK_METHOD2(GetAgcStatus, int(bool& enabled, AgcModes& mode));
80 MOCK_METHOD1(SetAgcConfig, int(AgcConfig config));
81 MOCK_METHOD1(GetAgcConfig, int(AgcConfig& config));
82 MOCK_METHOD2(SetEcStatus, int(bool enable, EcModes mode));
83 MOCK_METHOD2(GetEcStatus, int(bool& enabled, EcModes& mode));
84 MOCK_METHOD1(EnableDriftCompensation, int(bool enable));
85 MOCK_METHOD0(DriftCompensationEnabled, bool());
86 MOCK_METHOD1(SetDelayOffsetMs, void(int offset));
87 MOCK_METHOD0(DelayOffsetMs, int());
88 MOCK_METHOD2(SetAecmMode, int(AecmModes mode, bool enableCNG));
89 MOCK_METHOD2(GetAecmMode, int(AecmModes& mode, bool& enabledCNG));
90 MOCK_METHOD1(EnableHighPassFilter, int(bool enable));
91 MOCK_METHOD0(IsHighPassFilterEnabled, bool());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010092 MOCK_METHOD1(VoiceActivityIndicator, int(int channel));
93 MOCK_METHOD1(SetEcMetricsStatus, int(bool enable));
94 MOCK_METHOD1(GetEcMetricsStatus, int(bool& enabled));
95 MOCK_METHOD4(GetEchoMetrics, int(int& ERL, int& ERLE, int& RERL, int& A_NLP));
96 MOCK_METHOD3(GetEcDelayMetrics,
97 int(int& delay_median,
98 int& delay_std,
99 float& fraction_poor_delays));
100 MOCK_METHOD1(StartDebugRecording, int(const char* fileNameUTF8));
101 MOCK_METHOD1(StartDebugRecording, int(FILE* file_handle));
102 MOCK_METHOD0(StopDebugRecording, int());
103 MOCK_METHOD1(SetTypingDetectionStatus, int(bool enable));
104 MOCK_METHOD1(GetTypingDetectionStatus, int(bool& enabled));
105 MOCK_METHOD1(TimeSinceLastTyping, int(int& seconds));
106 MOCK_METHOD5(SetTypingDetectionParameters,
107 int(int timeWindow,
108 int costPerTyping,
109 int reportingThreshold,
110 int penaltyDecay,
111 int typeEventDelay));
112 MOCK_METHOD1(EnableStereoChannelSwapping, void(bool enable));
113 MOCK_METHOD0(IsStereoChannelSwappingEnabled, bool());
114
115 // VoEBase
116 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
117 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -0700118 MOCK_METHOD3(
119 Init,
120 int(AudioDeviceModule* external_adm,
121 AudioProcessing* audioproc,
122 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100123 MOCK_METHOD0(audio_processing, AudioProcessing*());
aleloidd310712016-11-17 06:28:59 -0800124 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100125 MOCK_METHOD0(Terminate, int());
126 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -0700127 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100128 MOCK_METHOD1(DeleteChannel, int(int channel));
129 MOCK_METHOD1(StartReceive, int(int channel));
130 MOCK_METHOD1(StopReceive, int(int channel));
131 MOCK_METHOD1(StartPlayout, int(int channel));
132 MOCK_METHOD1(StopPlayout, int(int channel));
133 MOCK_METHOD1(StartSend, int(int channel));
134 MOCK_METHOD1(StopSend, int(int channel));
135 MOCK_METHOD1(GetVersion, int(char version[1024]));
136 MOCK_METHOD0(LastError, int());
137 MOCK_METHOD0(audio_transport, AudioTransport*());
138 MOCK_METHOD2(AssociateSendChannel,
139 int(int channel, int accociate_send_channel));
140
141 // VoECodec
142 MOCK_METHOD0(NumOfCodecs, int());
143 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
144 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
145 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
146 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
147 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
148 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
149 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
150 MOCK_METHOD3(SetSendCNPayloadType,
151 int(int channel, int type, PayloadFrequencies frequency));
152 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
153 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
154 MOCK_METHOD4(SetVADStatus,
155 int(int channel, bool enable, VadModes mode, bool disableDTX));
156 MOCK_METHOD4(
157 GetVADStatus,
158 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
159 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
160 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100161
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100162 // VoEFile
163 MOCK_METHOD7(StartPlayingFileLocally,
164 int(int channel,
165 const char fileNameUTF8[1024],
166 bool loop,
167 FileFormats format,
168 float volumeScaling,
169 int startPointMs,
170 int stopPointMs));
171 MOCK_METHOD6(StartPlayingFileLocally,
172 int(int channel,
173 InStream* stream,
174 FileFormats format,
175 float volumeScaling,
176 int startPointMs,
177 int stopPointMs));
178 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
179 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
180 MOCK_METHOD6(StartPlayingFileAsMicrophone,
181 int(int channel,
182 const char fileNameUTF8[1024],
183 bool loop,
184 bool mixWithMicrophone,
185 FileFormats format,
186 float volumeScaling));
187 MOCK_METHOD5(StartPlayingFileAsMicrophone,
188 int(int channel,
189 InStream* stream,
190 bool mixWithMicrophone,
191 FileFormats format,
192 float volumeScaling));
193 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
194 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
195 MOCK_METHOD4(StartRecordingPlayout,
196 int(int channel,
197 const char* fileNameUTF8,
198 CodecInst* compression,
199 int maxSizeBytes));
200 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
201 MOCK_METHOD3(StartRecordingPlayout,
202 int(int channel, OutStream* stream, CodecInst* compression));
203 MOCK_METHOD3(StartRecordingMicrophone,
204 int(const char* fileNameUTF8,
205 CodecInst* compression,
206 int maxSizeBytes));
207 MOCK_METHOD2(StartRecordingMicrophone,
208 int(OutStream* stream, CodecInst* compression));
209 MOCK_METHOD0(StopRecordingMicrophone, int());
210
211 // VoEHardware
212 MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices));
213 MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices));
214 MOCK_METHOD3(GetRecordingDeviceName,
215 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
216 MOCK_METHOD3(GetPlayoutDeviceName,
217 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
218 MOCK_METHOD2(SetRecordingDevice,
219 int(int index, StereoChannel recordingChannel));
220 MOCK_METHOD1(SetPlayoutDevice, int(int index));
221 MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer));
222 MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer));
223 MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec));
224 MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec));
225 MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec));
226 MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec));
227 MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool());
228 MOCK_METHOD1(EnableBuiltInAEC, int(bool enable));
229 MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool());
230 MOCK_METHOD1(EnableBuiltInAGC, int(bool enable));
231 MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool());
232 MOCK_METHOD1(EnableBuiltInNS, int(bool enable));
233
234 // VoENetEqStats
235 MOCK_METHOD2(GetNetworkStatistics,
236 int(int channel, NetworkStatistics& stats));
237 MOCK_CONST_METHOD2(GetDecodingCallStatistics,
238 int(int channel, AudioDecodingCallStats* stats));
239
240 // VoENetwork
241 MOCK_METHOD2(RegisterExternalTransport,
242 int(int channel, Transport& transport));
243 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
244 MOCK_METHOD3(ReceivedRTPPacket,
245 int(int channel, const void* data, size_t length));
246 MOCK_METHOD4(ReceivedRTPPacket,
247 int(int channel,
248 const void* data,
249 size_t length,
250 const PacketTime& packet_time));
251 MOCK_METHOD3(ReceivedRTCPPacket,
252 int(int channel, const void* data, size_t length));
253
254 // VoERTP_RTCP
255 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
256 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
257 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
258 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
259 int(int channel, bool enable, unsigned char id));
260 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
261 int(int channel, bool enable, unsigned char id));
262 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
263 int(int channel, bool enable, unsigned char id));
264 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
265 int(int channel, bool enable, unsigned char id));
266 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
267 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
268 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
269 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
270 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
271 MOCK_METHOD7(GetRemoteRTCPData,
272 int(int channel,
273 unsigned int& NTPHigh,
274 unsigned int& NTPLow,
275 unsigned int& timestamp,
276 unsigned int& playoutTimestamp,
277 unsigned int* jitter,
278 unsigned short* fractionLost));
279 MOCK_METHOD4(GetRTPStatistics,
280 int(int channel,
281 unsigned int& averageJitterMs,
282 unsigned int& maxJitterMs,
283 unsigned int& discardedPackets));
284 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
285 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
286 int(int channel, std::vector<ReportBlock>* receive_blocks));
287 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
288 MOCK_METHOD3(GetREDStatus,
289 int(int channel, bool& enable, int& redPayloadtype));
290 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
291
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100292 // VoEVolumeControl
293 MOCK_METHOD1(SetSpeakerVolume, int(unsigned int volume));
294 MOCK_METHOD1(GetSpeakerVolume, int(unsigned int& volume));
295 MOCK_METHOD1(SetMicVolume, int(unsigned int volume));
296 MOCK_METHOD1(GetMicVolume, int(unsigned int& volume));
297 MOCK_METHOD2(SetInputMute, int(int channel, bool enable));
298 MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled));
299 MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level));
300 MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level));
301 MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level));
302 MOCK_METHOD2(GetSpeechOutputLevelFullRange,
303 int(int channel, unsigned& level));
304 MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling));
305 MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling));
306 MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right));
307 MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right));
ossu29b1a8d2016-06-13 07:34:51 -0700308
309 private:
310 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
311 // here, but due to how gmock is implemented, I cannot just keep it in the
312 // functor implementing the default version of ChannelProxyFactory, above.
313 // GMock creates an unfortunate copy of the functor, which would cause us to
314 // return a dangling reference. Fortunately, this should go away once
315 // voe::Channel does.
316 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800317
318 MockAudioDeviceModule mock_audio_device_;
319 MockAudioProcessing mock_audio_processing_;
320 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100321};
322} // namespace test
323} // namespace webrtc
324
325#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_