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