blob: 6b1f9cf31fabfa8976ffe922e774c4dbab336736 [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_));
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 }));
ossu29b1a8d2016-06-13 07:34:51 -070060 return proxy;
61 }));
aleloidd310712016-11-17 06:28:59 -080062
tommi8eb07512017-03-13 08:23:35 -070063 ON_CALL(mock_audio_device_, TimeUntilNextProcess())
64 .WillByDefault(testing::Return(1000));
aleloidd310712016-11-17 06:28:59 -080065 ON_CALL(*this, audio_device_module())
66 .WillByDefault(testing::Return(&mock_audio_device_));
67 ON_CALL(*this, audio_processing())
68 .WillByDefault(testing::Return(&mock_audio_processing_));
69 ON_CALL(*this, audio_transport())
70 .WillByDefault(testing::Return(&mock_audio_transport_));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010071 }
solenberg7602aab2016-11-14 11:30:07 -080072 virtual ~MockVoiceEngine() /* override */ {
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010073 // Decrease ref count before base class d-tor is called; otherwise it will
74 // trigger an assertion.
75 --_ref_count;
76 }
solenberg13725082015-11-25 08:16:52 -080077 // Allows injecting a ChannelProxy factory.
78 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id));
79
80 // VoiceEngineImpl
solenberg7602aab2016-11-14 11:30:07 -080081 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy(
nisseef8b61e2016-04-29 06:09:15 -070082 int channel_id) /* override */ {
kwibergb7f89d62016-02-17 10:04:18 -080083 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id));
solenberg13725082015-11-25 08:16:52 -080084 }
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010085
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010086 // VoEBase
87 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer));
88 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int());
ossu5f7cfa52016-05-30 08:11:28 -070089 MOCK_METHOD3(
90 Init,
91 int(AudioDeviceModule* external_adm,
92 AudioProcessing* audioproc,
93 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010094 MOCK_METHOD0(audio_processing, AudioProcessing*());
aleloidd310712016-11-17 06:28:59 -080095 MOCK_METHOD0(audio_device_module, AudioDeviceModule*());
solenberg796b8f92017-03-01 17:02:23 -080096 MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*());
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010097 MOCK_METHOD0(Terminate, int());
98 MOCK_METHOD0(CreateChannel, int());
solenberg88499ec2016-09-07 07:34:41 -070099 MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100100 MOCK_METHOD1(DeleteChannel, int(int channel));
101 MOCK_METHOD1(StartReceive, int(int channel));
102 MOCK_METHOD1(StopReceive, int(int channel));
103 MOCK_METHOD1(StartPlayout, int(int channel));
104 MOCK_METHOD1(StopPlayout, int(int channel));
105 MOCK_METHOD1(StartSend, int(int channel));
106 MOCK_METHOD1(StopSend, int(int channel));
107 MOCK_METHOD1(GetVersion, int(char version[1024]));
108 MOCK_METHOD0(LastError, int());
109 MOCK_METHOD0(audio_transport, AudioTransport*());
110 MOCK_METHOD2(AssociateSendChannel,
111 int(int channel, int accociate_send_channel));
112
113 // VoECodec
114 MOCK_METHOD0(NumOfCodecs, int());
115 MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec));
116 MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec));
117 MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec));
118 MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps));
119 MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec));
120 MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec));
121 MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec));
122 MOCK_METHOD3(SetSendCNPayloadType,
123 int(int channel, int type, PayloadFrequencies frequency));
124 MOCK_METHOD2(SetFECStatus, int(int channel, bool enable));
125 MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled));
126 MOCK_METHOD4(SetVADStatus,
127 int(int channel, bool enable, VadModes mode, bool disableDTX));
128 MOCK_METHOD4(
129 GetVADStatus,
130 int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX));
131 MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz));
132 MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100133
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100134 // VoEFile
135 MOCK_METHOD7(StartPlayingFileLocally,
136 int(int channel,
137 const char fileNameUTF8[1024],
138 bool loop,
139 FileFormats format,
140 float volumeScaling,
141 int startPointMs,
142 int stopPointMs));
143 MOCK_METHOD6(StartPlayingFileLocally,
144 int(int channel,
145 InStream* stream,
146 FileFormats format,
147 float volumeScaling,
148 int startPointMs,
149 int stopPointMs));
150 MOCK_METHOD1(StopPlayingFileLocally, int(int channel));
151 MOCK_METHOD1(IsPlayingFileLocally, int(int channel));
152 MOCK_METHOD6(StartPlayingFileAsMicrophone,
153 int(int channel,
154 const char fileNameUTF8[1024],
155 bool loop,
156 bool mixWithMicrophone,
157 FileFormats format,
158 float volumeScaling));
159 MOCK_METHOD5(StartPlayingFileAsMicrophone,
160 int(int channel,
161 InStream* stream,
162 bool mixWithMicrophone,
163 FileFormats format,
164 float volumeScaling));
165 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel));
166 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel));
167 MOCK_METHOD4(StartRecordingPlayout,
168 int(int channel,
169 const char* fileNameUTF8,
170 CodecInst* compression,
171 int maxSizeBytes));
172 MOCK_METHOD1(StopRecordingPlayout, int(int channel));
173 MOCK_METHOD3(StartRecordingPlayout,
174 int(int channel, OutStream* stream, CodecInst* compression));
175 MOCK_METHOD3(StartRecordingMicrophone,
176 int(const char* fileNameUTF8,
177 CodecInst* compression,
178 int maxSizeBytes));
179 MOCK_METHOD2(StartRecordingMicrophone,
180 int(OutStream* stream, CodecInst* compression));
181 MOCK_METHOD0(StopRecordingMicrophone, int());
182
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100183 // VoENetwork
184 MOCK_METHOD2(RegisterExternalTransport,
185 int(int channel, Transport& transport));
186 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel));
187 MOCK_METHOD3(ReceivedRTPPacket,
188 int(int channel, const void* data, size_t length));
189 MOCK_METHOD4(ReceivedRTPPacket,
190 int(int channel,
191 const void* data,
192 size_t length,
193 const PacketTime& packet_time));
194 MOCK_METHOD3(ReceivedRTCPPacket,
195 int(int channel, const void* data, size_t length));
196
197 // VoERTP_RTCP
198 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc));
199 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc));
200 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc));
201 MOCK_METHOD3(SetSendAudioLevelIndicationStatus,
202 int(int channel, bool enable, unsigned char id));
203 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus,
204 int(int channel, bool enable, unsigned char id));
205 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus,
206 int(int channel, bool enable, unsigned char id));
207 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus,
208 int(int channel, bool enable, unsigned char id));
209 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable));
210 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled));
211 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256]));
212 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256]));
213 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256]));
214 MOCK_METHOD7(GetRemoteRTCPData,
215 int(int channel,
216 unsigned int& NTPHigh,
217 unsigned int& NTPLow,
218 unsigned int& timestamp,
219 unsigned int& playoutTimestamp,
220 unsigned int* jitter,
221 unsigned short* fractionLost));
222 MOCK_METHOD4(GetRTPStatistics,
223 int(int channel,
224 unsigned int& averageJitterMs,
225 unsigned int& maxJitterMs,
226 unsigned int& discardedPackets));
227 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats));
228 MOCK_METHOD2(GetRemoteRTCPReportBlocks,
229 int(int channel, std::vector<ReportBlock>* receive_blocks));
230 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype));
231 MOCK_METHOD3(GetREDStatus,
232 int(int channel, bool& enable, int& redPayloadtype));
233 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets));
234
ossu29b1a8d2016-06-13 07:34:51 -0700235 private:
236 // TODO(ossu): I'm not particularly happy about keeping the decoder factory
237 // here, but due to how gmock is implemented, I cannot just keep it in the
238 // functor implementing the default version of ChannelProxyFactory, above.
239 // GMock creates an unfortunate copy of the functor, which would cause us to
240 // return a dangling reference. Fortunately, this should go away once
241 // voe::Channel does.
242 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
aleloidd310712016-11-17 06:28:59 -0800243
244 MockAudioDeviceModule mock_audio_device_;
245 MockAudioProcessing mock_audio_processing_;
246 MockAudioTransport mock_audio_transport_;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100247};
248} // namespace test
249} // namespace webrtc
250
251#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_