blob: 7c11f5d74bdc3719d28335c36fb669a83030e625 [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
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010079 // VoEBase
80 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
81 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -070082 MOCK_METHOD3(
83 Init,
84 int(AudioDeviceModule* external_adm,
85 AudioProcessing* audioproc,
86 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010087 MOCK_METHOD0(audio_processing, AudioProcessing*());
aleloidd310712016-11-17 06:28:59 -080088 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
solenberg796b8f92017-03-01 17:02:23 -080089 MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010090 MOCK_METHOD0(Terminate, int());
91 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -070092 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010093 MOCK_METHOD1(DeleteChannel, int(int channel));
94 MOCK_METHOD1(StartReceive, int(int channel));
95 MOCK_METHOD1(StopReceive, int(int channel));
96 MOCK_METHOD1(StartPlayout, int(int channel));
97 MOCK_METHOD1(StopPlayout, int(int channel));
98 MOCK_METHOD1(StartSend, int(int channel));
99 MOCK_METHOD1(StopSend, int(int channel));
100 MOCK_METHOD1(GetVersion, int(char version[1024]));
101 MOCK_METHOD0(LastError, int());
102 MOCK_METHOD0(audio_transport, AudioTransport*());
103 MOCK_METHOD2(AssociateSendChannel,
104 int(int channel, int accociate_send_channel));
105
106 // VoECodec
107 MOCK_METHOD0(NumOfCodecs, int());
108 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
109 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
110 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
111 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
112 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
113 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
114 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
115 MOCK_METHOD3(SetSendCNPayloadType,
116 int(int channel, int type, PayloadFrequencies frequency));
117 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
118 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
119 MOCK_METHOD4(SetVADStatus,
120 int(int channel, bool enable, VadModes mode, bool disableDTX));
121 MOCK_METHOD4(
122 GetVADStatus,
123 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
124 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
125 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100126
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100127 // VoEFile
128 MOCK_METHOD7(StartPlayingFileLocally,
129 int(int channel,
130 const char fileNameUTF8[1024],
131 bool loop,
132 FileFormats format,
133 float volumeScaling,
134 int startPointMs,
135 int stopPointMs));
136 MOCK_METHOD6(StartPlayingFileLocally,
137 int(int channel,
138 InStream* stream,
139 FileFormats format,
140 float volumeScaling,
141 int startPointMs,
142 int stopPointMs));
143 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
144 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
145 MOCK_METHOD6(StartPlayingFileAsMicrophone,
146 int(int channel,
147 const char fileNameUTF8[1024],
148 bool loop,
149 bool mixWithMicrophone,
150 FileFormats format,
151 float volumeScaling));
152 MOCK_METHOD5(StartPlayingFileAsMicrophone,
153 int(int channel,
154 InStream* stream,
155 bool mixWithMicrophone,
156 FileFormats format,
157 float volumeScaling));
158 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
159 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
160 MOCK_METHOD4(StartRecordingPlayout,
161 int(int channel,
162 const char* fileNameUTF8,
163 CodecInst* compression,
164 int maxSizeBytes));
165 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
166 MOCK_METHOD3(StartRecordingPlayout,
167 int(int channel, OutStream* stream, CodecInst* compression));
168 MOCK_METHOD3(StartRecordingMicrophone,
169 int(const char* fileNameUTF8,
170 CodecInst* compression,
171 int maxSizeBytes));
172 MOCK_METHOD2(StartRecordingMicrophone,
173 int(OutStream* stream, CodecInst* compression));
174 MOCK_METHOD0(StopRecordingMicrophone, int());
175
176 // VoEHardware
177 MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices));
178 MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices));
179 MOCK_METHOD3(GetRecordingDeviceName,
180 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
181 MOCK_METHOD3(GetPlayoutDeviceName,
182 int(int index, char strNameUTF8[128], char strGuidUTF8[128]));
183 MOCK_METHOD2(SetRecordingDevice,
184 int(int index, StereoChannel recordingChannel));
185 MOCK_METHOD1(SetPlayoutDevice, int(int index));
186 MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer));
187 MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer));
188 MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec));
189 MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec));
190 MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec));
191 MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec));
192 MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool());
193 MOCK_METHOD1(EnableBuiltInAEC, int(bool enable));
194 MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool());
195 MOCK_METHOD1(EnableBuiltInAGC, int(bool enable));
196 MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool());
197 MOCK_METHOD1(EnableBuiltInNS, int(bool enable));
198
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100199 // VoENetwork
200 MOCK_METHOD2(RegisterExternalTransport,
201 int(int channel, Transport& transport));
202 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
203 MOCK_METHOD3(ReceivedRTPPacket,
204 int(int channel, const void* data, size_t length));
205 MOCK_METHOD4(ReceivedRTPPacket,
206 int(int channel,
207 const void* data,
208 size_t length,
209 const PacketTime& packet_time));
210 MOCK_METHOD3(ReceivedRTCPPacket,
211 int(int channel, const void* data, size_t length));
212
213 // VoERTP_RTCP
214 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
215 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
216 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
217 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
218 int(int channel, bool enable, unsigned char id));
219 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
220 int(int channel, bool enable, unsigned char id));
221 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
222 int(int channel, bool enable, unsigned char id));
223 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
224 int(int channel, bool enable, unsigned char id));
225 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
226 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
227 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
228 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
229 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
230 MOCK_METHOD7(GetRemoteRTCPData,
231 int(int channel,
232 unsigned int& NTPHigh,
233 unsigned int& NTPLow,
234 unsigned int& timestamp,
235 unsigned int& playoutTimestamp,
236 unsigned int* jitter,
237 unsigned short* fractionLost));
238 MOCK_METHOD4(GetRTPStatistics,
239 int(int channel,
240 unsigned int& averageJitterMs,
241 unsigned int& maxJitterMs,
242 unsigned int& discardedPackets));
243 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
244 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
245 int(int channel, std::vector<ReportBlock>* receive_blocks));
246 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
247 MOCK_METHOD3(GetREDStatus,
248 int(int channel, bool& enable, int& redPayloadtype));
249 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
250
ossu29b1a8d2016-06-13 07:34:51 -0700251 private:
252 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
253 // here, but due to how gmock is implemented, I cannot just keep it in the
254 // functor implementing the default version of ChannelProxyFactory, above.
255 // GMock creates an unfortunate copy of the functor, which would cause us to
256 // return a dangling reference. Fortunately, this should go away once
257 // voe::Channel does.
258 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800259
260 MockAudioDeviceModule mock_audio_device_;
261 MockAudioProcessing mock_audio_processing_;
262 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100263};
264} // namespace test
265} // namespace webrtc
266
267#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_