blob: 7655d3b8443f6253fb0d6b14d53dc671c9f4d68c [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"
ossuc3d4b482017-05-23 06:07:11 -070019#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
kwiberg77eab702016-09-28 17:42:01 -070020#include "webrtc/test/gmock.h"
solenberg13725082015-11-25 08:16:52 -080021#include "webrtc/test/mock_voe_channel_proxy.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010022#include "webrtc/voice_engine/voice_engine_impl.h"
23
24namespace webrtc {
solenberg796b8f92017-03-01 17:02:23 -080025namespace voe {
26class TransmitMixer;
27} // namespace voe
28
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010029namespace test {
30
31// NOTE: This class inherits from VoiceEngineImpl so that its clients will be
32// able to get the various interfaces as usual, via T::GetInterface().
solenberg3a941542015-11-16 07:34:50 -080033class MockVoiceEngine : public VoiceEngineImpl {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010034 public:
nisseef8b61e2016-04-29 06:09:15 -070035 // TODO(nisse): Valid overrides commented out, because the gmock
36 // methods don't use any override declarations, and we want to avoid
37 // warnings from -Winconsistent-missing-override. See
38 // http://crbug.com/428099.
ossu29b1a8d2016-06-13 07:34:51 -070039 MockVoiceEngine(
40 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr)
solenberg88499ec2016-09-07 07:34:41 -070041 : decoder_factory_(decoder_factory) {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010042 // Increase ref count so this object isn't automatically deleted whenever
43 // interfaces are Release():d.
44 ++_ref_count;
solenberg13725082015-11-25 08:16:52 -080045 // We add this default behavior to make the mock easier to use in tests. It
46 // will create a NiceMock of a voe::ChannelProxy.
solenberg7602aab2016-11-14 11:30:07 -080047 // TODO(ossu): As long as AudioReceiveStream is implemented as a wrapper
ossu29b1a8d2016-06-13 07:34:51 -070048 // around Channel, we need to make sure ChannelProxy returns the same
49 // decoder factory as the one passed in when creating an AudioReceiveStream.
solenberg13725082015-11-25 08:16:52 -080050 ON_CALL(*this, ChannelProxyFactory(testing::_))
ossu29b1a8d2016-06-13 07:34:51 -070051 .WillByDefault(testing::Invoke([this](int channel_id) {
52 auto* proxy =
53 new testing::NiceMock<webrtc::test::MockVoEChannelProxy>();
54 EXPECT_CALL(*proxy, GetAudioDecoderFactory())
55 .WillRepeatedly(testing::ReturnRef(decoder_factory_));
kwiberg1c07c702017-03-27 07:15:49 -070056 EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_))
57 .WillRepeatedly(testing::Invoke(
58 [](const std::map<int, SdpAudioFormat>& codecs) {
59 EXPECT_THAT(codecs, testing::IsEmpty());
60 }));
ossuc3d4b482017-05-23 06:07:11 -070061 EXPECT_CALL(*proxy, GetRtpRtcp(testing::_, testing::_))
62 .WillRepeatedly(
63 testing::SetArgPointee<0>(GetMockRtpRtcp(channel_id)));
ossu29b1a8d2016-06-13 07:34:51 -070064 return proxy;
65 }));
aleloidd310712016-11-17 06:28:59 -080066
tommi8eb07512017-03-13 08:23:35 -070067 ON_CALL(mock_audio_device_, TimeUntilNextProcess())
68 .WillByDefault(testing::Return(1000));
aleloidd310712016-11-17 06:28:59 -080069 ON_CALL(*this, audio_device_module())
70 .WillByDefault(testing::Return(&mock_audio_device_));
71 ON_CALL(*this, audio_processing())
72 .WillByDefault(testing::Return(&mock_audio_processing_));
73 ON_CALL(*this, audio_transport())
74 .WillByDefault(testing::Return(&mock_audio_transport_));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010075 }
solenberg7602aab2016-11-14 11:30:07 -080076 virtual ~MockVoiceEngine() /* override */ {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010077 // Decrease ref count before base class d-tor is called; otherwise it will
78 // trigger an assertion.
79 --_ref_count;
80 }
ossuc3d4b482017-05-23 06:07:11 -070081
82 // These need to be the same each call to channel_id and must not leak.
83 MockRtpRtcp* GetMockRtpRtcp(int channel_id) {
84 if (mock_rtp_rtcps_.find(channel_id) == mock_rtp_rtcps_.end()) {
85 mock_rtp_rtcps_[channel_id].reset(new ::testing::NiceMock<MockRtpRtcp>);
86 }
87 return mock_rtp_rtcps_[channel_id].get();
88 }
89
solenberg13725082015-11-25 08:16:52 -080090 // Allows injecting a ChannelProxy factory.
91 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id));
92
93 // VoiceEngineImpl
solenberg7602aab2016-11-14 11:30:07 -080094 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy(
nisseef8b61e2016-04-29 06:09:15 -070095 int channel_id) /* override */ {
kwibergb7f89d62016-02-17 10:04:18 -080096 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id));
solenberg13725082015-11-25 08:16:52 -080097 }
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010098
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010099 // VoEBase
100 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
101 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -0700102 MOCK_METHOD3(
103 Init,
104 int(AudioDeviceModule* external_adm,
105 AudioProcessing* audioproc,
106 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100107 MOCK_METHOD0(audio_processing, AudioProcessing*());
aleloidd310712016-11-17 06:28:59 -0800108 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
solenberg796b8f92017-03-01 17:02:23 -0800109 MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100110 MOCK_METHOD0(Terminate, int());
111 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -0700112 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100113 MOCK_METHOD1(DeleteChannel, int(int channel));
114 MOCK_METHOD1(StartReceive, int(int channel));
115 MOCK_METHOD1(StopReceive, int(int channel));
116 MOCK_METHOD1(StartPlayout, int(int channel));
117 MOCK_METHOD1(StopPlayout, int(int channel));
118 MOCK_METHOD1(StartSend, int(int channel));
119 MOCK_METHOD1(StopSend, int(int channel));
120 MOCK_METHOD1(GetVersion, int(char version[1024]));
121 MOCK_METHOD0(LastError, int());
122 MOCK_METHOD0(audio_transport, AudioTransport*());
123 MOCK_METHOD2(AssociateSendChannel,
124 int(int channel, int accociate_send_channel));
125
126 // VoECodec
127 MOCK_METHOD0(NumOfCodecs, int());
128 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
129 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
130 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
131 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
132 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
133 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
134 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
135 MOCK_METHOD3(SetSendCNPayloadType,
136 int(int channel, int type, PayloadFrequencies frequency));
137 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
138 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
139 MOCK_METHOD4(SetVADStatus,
140 int(int channel, bool enable, VadModes mode, bool disableDTX));
141 MOCK_METHOD4(
142 GetVADStatus,
143 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
144 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
145 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100146
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100147 // VoEFile
148 MOCK_METHOD7(StartPlayingFileLocally,
149 int(int channel,
150 const char fileNameUTF8[1024],
151 bool loop,
152 FileFormats format,
153 float volumeScaling,
154 int startPointMs,
155 int stopPointMs));
156 MOCK_METHOD6(StartPlayingFileLocally,
157 int(int channel,
158 InStream* stream,
159 FileFormats format,
160 float volumeScaling,
161 int startPointMs,
162 int stopPointMs));
163 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
164 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
165 MOCK_METHOD6(StartPlayingFileAsMicrophone,
166 int(int channel,
167 const char fileNameUTF8[1024],
168 bool loop,
169 bool mixWithMicrophone,
170 FileFormats format,
171 float volumeScaling));
172 MOCK_METHOD5(StartPlayingFileAsMicrophone,
173 int(int channel,
174 InStream* stream,
175 bool mixWithMicrophone,
176 FileFormats format,
177 float volumeScaling));
178 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
179 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
180 MOCK_METHOD4(StartRecordingPlayout,
181 int(int channel,
182 const char* fileNameUTF8,
183 CodecInst* compression,
184 int maxSizeBytes));
185 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
186 MOCK_METHOD3(StartRecordingPlayout,
187 int(int channel, OutStream* stream, CodecInst* compression));
188 MOCK_METHOD3(StartRecordingMicrophone,
189 int(const char* fileNameUTF8,
190 CodecInst* compression,
191 int maxSizeBytes));
192 MOCK_METHOD2(StartRecordingMicrophone,
193 int(OutStream* stream, CodecInst* compression));
194 MOCK_METHOD0(StopRecordingMicrophone, int());
195
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100196 // VoENetwork
197 MOCK_METHOD2(RegisterExternalTransport,
198 int(int channel, Transport& transport));
199 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
200 MOCK_METHOD3(ReceivedRTPPacket,
201 int(int channel, const void* data, size_t length));
202 MOCK_METHOD4(ReceivedRTPPacket,
203 int(int channel,
204 const void* data,
205 size_t length,
206 const PacketTime& packet_time));
207 MOCK_METHOD3(ReceivedRTCPPacket,
208 int(int channel, const void* data, size_t length));
209
210 // VoERTP_RTCP
211 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
212 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
213 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
214 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
215 int(int channel, bool enable, unsigned char id));
216 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
217 int(int channel, bool enable, unsigned char id));
218 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
219 int(int channel, bool enable, unsigned char id));
220 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
221 int(int channel, bool enable, unsigned char id));
222 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
223 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
224 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
225 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
226 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
227 MOCK_METHOD7(GetRemoteRTCPData,
228 int(int channel,
229 unsigned int& NTPHigh,
230 unsigned int& NTPLow,
231 unsigned int& timestamp,
232 unsigned int& playoutTimestamp,
233 unsigned int* jitter,
234 unsigned short* fractionLost));
235 MOCK_METHOD4(GetRTPStatistics,
236 int(int channel,
237 unsigned int& averageJitterMs,
238 unsigned int& maxJitterMs,
239 unsigned int& discardedPackets));
240 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
241 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
242 int(int channel, std::vector<ReportBlock>* receive_blocks));
243 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
244 MOCK_METHOD3(GetREDStatus,
245 int(int channel, bool& enable, int& redPayloadtype));
246 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
247
ossu29b1a8d2016-06-13 07:34:51 -0700248 private:
249 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
250 // here, but due to how gmock is implemented, I cannot just keep it in the
251 // functor implementing the default version of ChannelProxyFactory, above.
252 // GMock creates an unfortunate copy of the functor, which would cause us to
253 // return a dangling reference. Fortunately, this should go away once
254 // voe::Channel does.
255 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800256
ossuc3d4b482017-05-23 06:07:11 -0700257 std::map<int, std::unique_ptr<MockRtpRtcp>> mock_rtp_rtcps_;
258
aleloidd310712016-11-17 06:28:59 -0800259 MockAudioDeviceModule mock_audio_device_;
260 MockAudioProcessing mock_audio_processing_;
261 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100262};
263} // namespace test
264} // namespace webrtc
265
266#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_