blob: e8eb5a263488d478c39511e025c696451870e113 [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"
ossuc3d4b482017-05-23 06:07:11 -070018#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.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_));
kwiberg1c07c702017-03-27 07:15:49 -070055 EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_))
56 .WillRepeatedly(testing::Invoke(
57 [](const std::map<int, SdpAudioFormat>& codecs) {
58 EXPECT_THAT(codecs, testing::IsEmpty());
59 }));
ossuc3d4b482017-05-23 06:07:11 -070060 EXPECT_CALL(*proxy, GetRtpRtcp(testing::_, testing::_))
61 .WillRepeatedly(
62 testing::SetArgPointee<0>(GetMockRtpRtcp(channel_id)));
ossu29b1a8d2016-06-13 07:34:51 -070063 return proxy;
64 }));
aleloidd310712016-11-17 06:28:59 -080065
tommi8eb07512017-03-13 08:23:35 -070066 ON_CALL(mock_audio_device_, TimeUntilNextProcess())
67 .WillByDefault(testing::Return(1000));
aleloidd310712016-11-17 06:28:59 -080068 ON_CALL(*this, audio_device_module())
69 .WillByDefault(testing::Return(&mock_audio_device_));
aleloidd310712016-11-17 06:28:59 -080070 ON_CALL(*this, audio_transport())
71 .WillByDefault(testing::Return(&mock_audio_transport_));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010072 }
solenberg7602aab2016-11-14 11:30:07 -080073 virtual ~MockVoiceEngine() /* override */ {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010074 // Decrease ref count before base class d-tor is called; otherwise it will
75 // trigger an assertion.
76 --_ref_count;
77 }
ossuc3d4b482017-05-23 06:07:11 -070078
79 // These need to be the same each call to channel_id and must not leak.
80 MockRtpRtcp* GetMockRtpRtcp(int channel_id) {
81 if (mock_rtp_rtcps_.find(channel_id) == mock_rtp_rtcps_.end()) {
82 mock_rtp_rtcps_[channel_id].reset(new ::testing::NiceMock<MockRtpRtcp>);
83 }
84 return mock_rtp_rtcps_[channel_id].get();
85 }
86
solenberg13725082015-11-25 08:16:52 -080087 // Allows injecting a ChannelProxy factory.
88 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id));
89
90 // VoiceEngineImpl
solenberg7602aab2016-11-14 11:30:07 -080091 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy(
nisseef8b61e2016-04-29 06:09:15 -070092 int channel_id) /* override */ {
kwibergb7f89d62016-02-17 10:04:18 -080093 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id));
solenberg13725082015-11-25 08:16:52 -080094 }
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010095
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010096 // VoEBase
97 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
98 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -070099 MOCK_METHOD3(
100 Init,
101 int(AudioDeviceModule* external_adm,
peaha9cc40b2017-06-29 08:32:09 -0700102 AudioProcessing* external_apm,
ossu5f7cfa52016-05-30 08:11:28 -0700103 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
aleloidd310712016-11-17 06:28:59 -0800104 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
solenberg796b8f92017-03-01 17:02:23 -0800105 MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100106 MOCK_METHOD0(Terminate, int());
107 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -0700108 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100109 MOCK_METHOD1(DeleteChannel, int(int channel));
110 MOCK_METHOD1(StartReceive, int(int channel));
111 MOCK_METHOD1(StopReceive, int(int channel));
112 MOCK_METHOD1(StartPlayout, int(int channel));
113 MOCK_METHOD1(StopPlayout, int(int channel));
114 MOCK_METHOD1(StartSend, int(int channel));
115 MOCK_METHOD1(StopSend, int(int channel));
116 MOCK_METHOD1(GetVersion, int(char version[1024]));
117 MOCK_METHOD0(LastError, int());
118 MOCK_METHOD0(audio_transport, AudioTransport*());
119 MOCK_METHOD2(AssociateSendChannel,
120 int(int channel, int accociate_send_channel));
121
122 // VoECodec
123 MOCK_METHOD0(NumOfCodecs, int());
124 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
125 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
126 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
127 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
128 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
129 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
130 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
131 MOCK_METHOD3(SetSendCNPayloadType,
132 int(int channel, int type, PayloadFrequencies frequency));
133 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
134 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
135 MOCK_METHOD4(SetVADStatus,
136 int(int channel, bool enable, VadModes mode, bool disableDTX));
137 MOCK_METHOD4(
138 GetVADStatus,
139 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
140 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
141 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100142
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100143 // VoEFile
144 MOCK_METHOD7(StartPlayingFileLocally,
145 int(int channel,
146 const char fileNameUTF8[1024],
147 bool loop,
148 FileFormats format,
149 float volumeScaling,
150 int startPointMs,
151 int stopPointMs));
152 MOCK_METHOD6(StartPlayingFileLocally,
153 int(int channel,
154 InStream* stream,
155 FileFormats format,
156 float volumeScaling,
157 int startPointMs,
158 int stopPointMs));
159 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
160 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
161 MOCK_METHOD6(StartPlayingFileAsMicrophone,
162 int(int channel,
163 const char fileNameUTF8[1024],
164 bool loop,
165 bool mixWithMicrophone,
166 FileFormats format,
167 float volumeScaling));
168 MOCK_METHOD5(StartPlayingFileAsMicrophone,
169 int(int channel,
170 InStream* stream,
171 bool mixWithMicrophone,
172 FileFormats format,
173 float volumeScaling));
174 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
175 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
176 MOCK_METHOD4(StartRecordingPlayout,
177 int(int channel,
178 const char* fileNameUTF8,
179 CodecInst* compression,
180 int maxSizeBytes));
181 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
182 MOCK_METHOD3(StartRecordingPlayout,
183 int(int channel, OutStream* stream, CodecInst* compression));
184 MOCK_METHOD3(StartRecordingMicrophone,
185 int(const char* fileNameUTF8,
186 CodecInst* compression,
187 int maxSizeBytes));
188 MOCK_METHOD2(StartRecordingMicrophone,
189 int(OutStream* stream, CodecInst* compression));
190 MOCK_METHOD0(StopRecordingMicrophone, int());
191
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100192 // VoENetwork
193 MOCK_METHOD2(RegisterExternalTransport,
194 int(int channel, Transport& transport));
195 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
196 MOCK_METHOD3(ReceivedRTPPacket,
197 int(int channel, const void* data, size_t length));
198 MOCK_METHOD4(ReceivedRTPPacket,
199 int(int channel,
200 const void* data,
201 size_t length,
202 const PacketTime& packet_time));
203 MOCK_METHOD3(ReceivedRTCPPacket,
204 int(int channel, const void* data, size_t length));
205
206 // VoERTP_RTCP
207 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
208 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
209 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
210 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
211 int(int channel, bool enable, unsigned char id));
212 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
213 int(int channel, bool enable, unsigned char id));
214 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
215 int(int channel, bool enable, unsigned char id));
216 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
217 int(int channel, bool enable, unsigned char id));
218 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
219 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
220 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
221 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
222 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
223 MOCK_METHOD7(GetRemoteRTCPData,
224 int(int channel,
225 unsigned int& NTPHigh,
226 unsigned int& NTPLow,
227 unsigned int& timestamp,
228 unsigned int& playoutTimestamp,
229 unsigned int* jitter,
230 unsigned short* fractionLost));
231 MOCK_METHOD4(GetRTPStatistics,
232 int(int channel,
233 unsigned int& averageJitterMs,
234 unsigned int& maxJitterMs,
235 unsigned int& discardedPackets));
236 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
237 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
238 int(int channel, std::vector<ReportBlock>* receive_blocks));
239 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
240 MOCK_METHOD3(GetREDStatus,
241 int(int channel, bool& enable, int& redPayloadtype));
242 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
243
ossu29b1a8d2016-06-13 07:34:51 -0700244 private:
245 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
246 // here, but due to how gmock is implemented, I cannot just keep it in the
247 // functor implementing the default version of ChannelProxyFactory, above.
248 // GMock creates an unfortunate copy of the functor, which would cause us to
249 // return a dangling reference. Fortunately, this should go away once
250 // voe::Channel does.
251 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800252
ossuc3d4b482017-05-23 06:07:11 -0700253 std::map<int, std::unique_ptr<MockRtpRtcp>> mock_rtp_rtcps_;
254
aleloidd310712016-11-17 06:28:59 -0800255 MockAudioDeviceModule mock_audio_device_;
aleloidd310712016-11-17 06:28:59 -0800256 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100257};
258} // namespace test
259} // namespace webrtc
260
261#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_