blob: cdb6a783dadc656121b793ec8ea35509fed89901 [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
tommi8eb07512017-03-13 08:23:35 -070058 ON_CALL(mock_audio_device_, TimeUntilNextProcess())
59 .WillByDefault(testing::Return(1000));
aleloidd310712016-11-17 06:28:59 -080060 ON_CALL(*this, audio_device_module())
61 .WillByDefault(testing::Return(&mock_audio_device_));
62 ON_CALL(*this, audio_processing())
63 .WillByDefault(testing::Return(&mock_audio_processing_));
64 ON_CALL(*this, audio_transport())
65 .WillByDefault(testing::Return(&mock_audio_transport_));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010066 }
solenberg7602aab2016-11-14 11:30:07 -080067 virtual ~MockVoiceEngine() /* override */ {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010068 // Decrease ref count before base class d-tor is called; otherwise it will
69 // trigger an assertion.
70 --_ref_count;
71 }
solenberg13725082015-11-25 08:16:52 -080072 // Allows injecting a ChannelProxy factory.
73 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id));
74
75 // VoiceEngineImpl
solenberg7602aab2016-11-14 11:30:07 -080076 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy(
nisseef8b61e2016-04-29 06:09:15 -070077 int channel_id) /* override */ {
kwibergb7f89d62016-02-17 10:04:18 -080078 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id));
solenberg13725082015-11-25 08:16:52 -080079 }
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010080
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010081 // VoEBase
82 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
83 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -070084 MOCK_METHOD3(
85 Init,
86 int(AudioDeviceModule* external_adm,
87 AudioProcessing* audioproc,
88 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010089 MOCK_METHOD0(audio_processing, AudioProcessing*());
aleloidd310712016-11-17 06:28:59 -080090 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
solenberg796b8f92017-03-01 17:02:23 -080091 MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010092 MOCK_METHOD0(Terminate, int());
93 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -070094 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010095 MOCK_METHOD1(DeleteChannel, int(int channel));
96 MOCK_METHOD1(StartReceive, int(int channel));
97 MOCK_METHOD1(StopReceive, int(int channel));
98 MOCK_METHOD1(StartPlayout, int(int channel));
99 MOCK_METHOD1(StopPlayout, int(int channel));
100 MOCK_METHOD1(StartSend, int(int channel));
101 MOCK_METHOD1(StopSend, int(int channel));
102 MOCK_METHOD1(GetVersion, int(char version[1024]));
103 MOCK_METHOD0(LastError, int());
104 MOCK_METHOD0(audio_transport, AudioTransport*());
105 MOCK_METHOD2(AssociateSendChannel,
106 int(int channel, int accociate_send_channel));
107
108 // VoECodec
109 MOCK_METHOD0(NumOfCodecs, int());
110 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
111 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
112 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
113 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
114 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
115 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
116 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
117 MOCK_METHOD3(SetSendCNPayloadType,
118 int(int channel, int type, PayloadFrequencies frequency));
119 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
120 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
121 MOCK_METHOD4(SetVADStatus,
122 int(int channel, bool enable, VadModes mode, bool disableDTX));
123 MOCK_METHOD4(
124 GetVADStatus,
125 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
126 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
127 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100128
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100129 // VoEFile
130 MOCK_METHOD7(StartPlayingFileLocally,
131 int(int channel,
132 const char fileNameUTF8[1024],
133 bool loop,
134 FileFormats format,
135 float volumeScaling,
136 int startPointMs,
137 int stopPointMs));
138 MOCK_METHOD6(StartPlayingFileLocally,
139 int(int channel,
140 InStream* stream,
141 FileFormats format,
142 float volumeScaling,
143 int startPointMs,
144 int stopPointMs));
145 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
146 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
147 MOCK_METHOD6(StartPlayingFileAsMicrophone,
148 int(int channel,
149 const char fileNameUTF8[1024],
150 bool loop,
151 bool mixWithMicrophone,
152 FileFormats format,
153 float volumeScaling));
154 MOCK_METHOD5(StartPlayingFileAsMicrophone,
155 int(int channel,
156 InStream* stream,
157 bool mixWithMicrophone,
158 FileFormats format,
159 float volumeScaling));
160 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
161 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
162 MOCK_METHOD4(StartRecordingPlayout,
163 int(int channel,
164 const char* fileNameUTF8,
165 CodecInst* compression,
166 int maxSizeBytes));
167 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
168 MOCK_METHOD3(StartRecordingPlayout,
169 int(int channel, OutStream* stream, CodecInst* compression));
170 MOCK_METHOD3(StartRecordingMicrophone,
171 int(const char* fileNameUTF8,
172 CodecInst* compression,
173 int maxSizeBytes));
174 MOCK_METHOD2(StartRecordingMicrophone,
175 int(OutStream* stream, CodecInst* compression));
176 MOCK_METHOD0(StopRecordingMicrophone, int());
177
178 // VoEHardware
179 MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices));
180 MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices));
181 MOCK_METHOD3(GetRecordingDeviceName,
182 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
183 MOCK_METHOD3(GetPlayoutDeviceName,
184 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
185 MOCK_METHOD2(SetRecordingDevice,
186 int(int index, StereoChannel recordingChannel));
187 MOCK_METHOD1(SetPlayoutDevice, int(int index));
188 MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer));
189 MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer));
190 MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec));
191 MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec));
192 MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec));
193 MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec));
194 MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool());
195 MOCK_METHOD1(EnableBuiltInAEC, int(bool enable));
196 MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool());
197 MOCK_METHOD1(EnableBuiltInAGC, int(bool enable));
198 MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool());
199 MOCK_METHOD1(EnableBuiltInNS, int(bool enable));
200
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100201 // VoENetwork
202 MOCK_METHOD2(RegisterExternalTransport,
203 int(int channel, Transport& transport));
204 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
205 MOCK_METHOD3(ReceivedRTPPacket,
206 int(int channel, const void* data, size_t length));
207 MOCK_METHOD4(ReceivedRTPPacket,
208 int(int channel,
209 const void* data,
210 size_t length,
211 const PacketTime& packet_time));
212 MOCK_METHOD3(ReceivedRTCPPacket,
213 int(int channel, const void* data, size_t length));
214
215 // VoERTP_RTCP
216 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
217 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
218 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
219 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
220 int(int channel, bool enable, unsigned char id));
221 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
222 int(int channel, bool enable, unsigned char id));
223 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
224 int(int channel, bool enable, unsigned char id));
225 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
226 int(int channel, bool enable, unsigned char id));
227 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
228 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
229 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
230 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
231 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
232 MOCK_METHOD7(GetRemoteRTCPData,
233 int(int channel,
234 unsigned int& NTPHigh,
235 unsigned int& NTPLow,
236 unsigned int& timestamp,
237 unsigned int& playoutTimestamp,
238 unsigned int* jitter,
239 unsigned short* fractionLost));
240 MOCK_METHOD4(GetRTPStatistics,
241 int(int channel,
242 unsigned int& averageJitterMs,
243 unsigned int& maxJitterMs,
244 unsigned int& discardedPackets));
245 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
246 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
247 int(int channel, std::vector<ReportBlock>* receive_blocks));
248 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
249 MOCK_METHOD3(GetREDStatus,
250 int(int channel, bool& enable, int& redPayloadtype));
251 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
252
ossu29b1a8d2016-06-13 07:34:51 -0700253 private:
254 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
255 // here, but due to how gmock is implemented, I cannot just keep it in the
256 // functor implementing the default version of ChannelProxyFactory, above.
257 // GMock creates an unfortunate copy of the functor, which would cause us to
258 // return a dangling reference. Fortunately, this should go away once
259 // voe::Channel does.
260 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800261
262 MockAudioDeviceModule mock_audio_device_;
263 MockAudioProcessing mock_audio_processing_;
264 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100265};
266} // namespace test
267} // namespace webrtc
268
269#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_