blob: ca3fe4f4667557d32cfcab03a84ae4c18f4b5d53 [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
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100178 // VoENetwork
179 MOCK_METHOD2(RegisterExternalTransport,
180 int(int channel, Transport& transport));
181 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
182 MOCK_METHOD3(ReceivedRTPPacket,
183 int(int channel, const void* data, size_t length));
184 MOCK_METHOD4(ReceivedRTPPacket,
185 int(int channel,
186 const void* data,
187 size_t length,
188 const PacketTime& packet_time));
189 MOCK_METHOD3(ReceivedRTCPPacket,
190 int(int channel, const void* data, size_t length));
191
192 // VoERTP_RTCP
193 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
194 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
195 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
196 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
197 int(int channel, bool enable, unsigned char id));
198 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
199 int(int channel, bool enable, unsigned char id));
200 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
201 int(int channel, bool enable, unsigned char id));
202 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
203 int(int channel, bool enable, unsigned char id));
204 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
205 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
206 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
207 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
208 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
209 MOCK_METHOD7(GetRemoteRTCPData,
210 int(int channel,
211 unsigned int& NTPHigh,
212 unsigned int& NTPLow,
213 unsigned int& timestamp,
214 unsigned int& playoutTimestamp,
215 unsigned int* jitter,
216 unsigned short* fractionLost));
217 MOCK_METHOD4(GetRTPStatistics,
218 int(int channel,
219 unsigned int& averageJitterMs,
220 unsigned int& maxJitterMs,
221 unsigned int& discardedPackets));
222 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
223 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
224 int(int channel, std::vector<ReportBlock>* receive_blocks));
225 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
226 MOCK_METHOD3(GetREDStatus,
227 int(int channel, bool& enable, int& redPayloadtype));
228 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
229
ossu29b1a8d2016-06-13 07:34:51 -0700230 private:
231 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
232 // here, but due to how gmock is implemented, I cannot just keep it in the
233 // functor implementing the default version of ChannelProxyFactory, above.
234 // GMock creates an unfortunate copy of the functor, which would cause us to
235 // return a dangling reference. Fortunately, this should go away once
236 // voe::Channel does.
237 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800238
239 MockAudioDeviceModule mock_audio_device_;
240 MockAudioProcessing mock_audio_processing_;
241 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100242};
243} // namespace test
244} // namespace webrtc
245
246#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_