1 /* 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 14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "webrtc/test/mock_voe_channel_proxy.h" 16 #include "webrtc/voice_engine/voice_engine_impl.h" 17 18 namespace webrtc { 19 namespace test { 20 21 // NOTE: This class inherits from VoiceEngineImpl so that its clients will be 22 // able to get the various interfaces as usual, via T::GetInterface(). 23 class MockVoiceEngine : public VoiceEngineImpl { 24 public: MockVoiceEngine()25 MockVoiceEngine() : VoiceEngineImpl(new Config(), true) { 26 // Increase ref count so this object isn't automatically deleted whenever 27 // interfaces are Release():d. 28 ++_ref_count; 29 // We add this default behavior to make the mock easier to use in tests. It 30 // will create a NiceMock of a voe::ChannelProxy. 31 ON_CALL(*this, ChannelProxyFactory(testing::_)) 32 .WillByDefault( 33 testing::Invoke([](int channel_id) { 34 return new testing::NiceMock<MockVoEChannelProxy>(); 35 })); 36 } ~MockVoiceEngine()37 ~MockVoiceEngine() override { 38 // Decrease ref count before base class d-tor is called; otherwise it will 39 // trigger an assertion. 40 --_ref_count; 41 } 42 // Allows injecting a ChannelProxy factory. 43 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); 44 45 // VoiceEngineImpl GetChannelProxy(int channel_id)46 rtc::scoped_ptr<voe::ChannelProxy> GetChannelProxy(int channel_id) override { 47 return rtc::scoped_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); 48 } 49 50 // VoEAudioProcessing 51 MOCK_METHOD2(SetNsStatus, int(bool enable, NsModes mode)); 52 MOCK_METHOD2(GetNsStatus, int(bool& enabled, NsModes& mode)); 53 MOCK_METHOD2(SetAgcStatus, int(bool enable, AgcModes mode)); 54 MOCK_METHOD2(GetAgcStatus, int(bool& enabled, AgcModes& mode)); 55 MOCK_METHOD1(SetAgcConfig, int(AgcConfig config)); 56 MOCK_METHOD1(GetAgcConfig, int(AgcConfig& config)); 57 MOCK_METHOD2(SetEcStatus, int(bool enable, EcModes mode)); 58 MOCK_METHOD2(GetEcStatus, int(bool& enabled, EcModes& mode)); 59 MOCK_METHOD1(EnableDriftCompensation, int(bool enable)); 60 MOCK_METHOD0(DriftCompensationEnabled, bool()); 61 MOCK_METHOD1(SetDelayOffsetMs, void(int offset)); 62 MOCK_METHOD0(DelayOffsetMs, int()); 63 MOCK_METHOD2(SetAecmMode, int(AecmModes mode, bool enableCNG)); 64 MOCK_METHOD2(GetAecmMode, int(AecmModes& mode, bool& enabledCNG)); 65 MOCK_METHOD1(EnableHighPassFilter, int(bool enable)); 66 MOCK_METHOD0(IsHighPassFilterEnabled, bool()); 67 MOCK_METHOD3(SetRxNsStatus, int(int channel, bool enable, NsModes mode)); 68 MOCK_METHOD3(GetRxNsStatus, int(int channel, bool& enabled, NsModes& mode)); 69 MOCK_METHOD3(SetRxAgcStatus, int(int channel, bool enable, AgcModes mode)); 70 MOCK_METHOD3(GetRxAgcStatus, int(int channel, bool& enabled, AgcModes& mode)); 71 MOCK_METHOD2(SetRxAgcConfig, int(int channel, AgcConfig config)); 72 MOCK_METHOD2(GetRxAgcConfig, int(int channel, AgcConfig& config)); 73 MOCK_METHOD2(RegisterRxVadObserver, 74 int(int channel, VoERxVadCallback& observer)); 75 MOCK_METHOD1(DeRegisterRxVadObserver, int(int channel)); 76 MOCK_METHOD1(VoiceActivityIndicator, int(int channel)); 77 MOCK_METHOD1(SetEcMetricsStatus, int(bool enable)); 78 MOCK_METHOD1(GetEcMetricsStatus, int(bool& enabled)); 79 MOCK_METHOD4(GetEchoMetrics, int(int& ERL, int& ERLE, int& RERL, int& A_NLP)); 80 MOCK_METHOD3(GetEcDelayMetrics, 81 int(int& delay_median, 82 int& delay_std, 83 float& fraction_poor_delays)); 84 MOCK_METHOD1(StartDebugRecording, int(const char* fileNameUTF8)); 85 MOCK_METHOD1(StartDebugRecording, int(FILE* file_handle)); 86 MOCK_METHOD0(StopDebugRecording, int()); 87 MOCK_METHOD1(SetTypingDetectionStatus, int(bool enable)); 88 MOCK_METHOD1(GetTypingDetectionStatus, int(bool& enabled)); 89 MOCK_METHOD1(TimeSinceLastTyping, int(int& seconds)); 90 MOCK_METHOD5(SetTypingDetectionParameters, 91 int(int timeWindow, 92 int costPerTyping, 93 int reportingThreshold, 94 int penaltyDecay, 95 int typeEventDelay)); 96 MOCK_METHOD1(EnableStereoChannelSwapping, void(bool enable)); 97 MOCK_METHOD0(IsStereoChannelSwappingEnabled, bool()); 98 99 // VoEBase 100 MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer)); 101 MOCK_METHOD0(DeRegisterVoiceEngineObserver, int()); 102 MOCK_METHOD2(Init, 103 int(AudioDeviceModule* external_adm, 104 AudioProcessing* audioproc)); 105 MOCK_METHOD0(audio_processing, AudioProcessing*()); 106 MOCK_METHOD0(Terminate, int()); 107 MOCK_METHOD0(CreateChannel, int()); 108 MOCK_METHOD1(CreateChannel, int(const Config& config)); 109 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)); 142 MOCK_METHOD0(GetEventLog, RtcEventLog*()); 143 144 // VoEDtmf 145 MOCK_METHOD5(SendTelephoneEvent, 146 int(int channel, 147 int eventCode, 148 bool outOfBand, 149 int lengthMs, 150 int attenuationDb)); 151 MOCK_METHOD2(SetSendTelephoneEventPayloadType, 152 int(int channel, unsigned char type)); 153 MOCK_METHOD2(GetSendTelephoneEventPayloadType, 154 int(int channel, unsigned char& type)); 155 MOCK_METHOD2(SetDtmfFeedbackStatus, int(bool enable, bool directFeedback)); 156 MOCK_METHOD2(GetDtmfFeedbackStatus, int(bool& enabled, bool& directFeedback)); 157 MOCK_METHOD3(PlayDtmfTone, 158 int(int eventCode, int lengthMs, int attenuationDb)); 159 160 // VoEExternalMedia 161 MOCK_METHOD3(RegisterExternalMediaProcessing, 162 int(int channel, 163 ProcessingTypes type, 164 VoEMediaProcess& processObject)); 165 MOCK_METHOD2(DeRegisterExternalMediaProcessing, 166 int(int channel, ProcessingTypes type)); 167 MOCK_METHOD3(GetAudioFrame, 168 int(int channel, int desired_sample_rate_hz, AudioFrame* frame)); 169 MOCK_METHOD2(SetExternalMixing, int(int channel, bool enable)); 170 171 // VoEFile 172 MOCK_METHOD7(StartPlayingFileLocally, 173 int(int channel, 174 const char fileNameUTF8[1024], 175 bool loop, 176 FileFormats format, 177 float volumeScaling, 178 int startPointMs, 179 int stopPointMs)); 180 MOCK_METHOD6(StartPlayingFileLocally, 181 int(int channel, 182 InStream* stream, 183 FileFormats format, 184 float volumeScaling, 185 int startPointMs, 186 int stopPointMs)); 187 MOCK_METHOD1(StopPlayingFileLocally, int(int channel)); 188 MOCK_METHOD1(IsPlayingFileLocally, int(int channel)); 189 MOCK_METHOD6(StartPlayingFileAsMicrophone, 190 int(int channel, 191 const char fileNameUTF8[1024], 192 bool loop, 193 bool mixWithMicrophone, 194 FileFormats format, 195 float volumeScaling)); 196 MOCK_METHOD5(StartPlayingFileAsMicrophone, 197 int(int channel, 198 InStream* stream, 199 bool mixWithMicrophone, 200 FileFormats format, 201 float volumeScaling)); 202 MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel)); 203 MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel)); 204 MOCK_METHOD4(StartRecordingPlayout, 205 int(int channel, 206 const char* fileNameUTF8, 207 CodecInst* compression, 208 int maxSizeBytes)); 209 MOCK_METHOD1(StopRecordingPlayout, int(int channel)); 210 MOCK_METHOD3(StartRecordingPlayout, 211 int(int channel, OutStream* stream, CodecInst* compression)); 212 MOCK_METHOD3(StartRecordingMicrophone, 213 int(const char* fileNameUTF8, 214 CodecInst* compression, 215 int maxSizeBytes)); 216 MOCK_METHOD2(StartRecordingMicrophone, 217 int(OutStream* stream, CodecInst* compression)); 218 MOCK_METHOD0(StopRecordingMicrophone, int()); 219 220 // VoEHardware 221 MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices)); 222 MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices)); 223 MOCK_METHOD3(GetRecordingDeviceName, 224 int(int index, char strNameUTF8[128], char strGuidUTF8[128])); 225 MOCK_METHOD3(GetPlayoutDeviceName, 226 int(int index, char strNameUTF8[128], char strGuidUTF8[128])); 227 MOCK_METHOD2(SetRecordingDevice, 228 int(int index, StereoChannel recordingChannel)); 229 MOCK_METHOD1(SetPlayoutDevice, int(int index)); 230 MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer)); 231 MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer)); 232 MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec)); 233 MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec)); 234 MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec)); 235 MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec)); 236 MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool()); 237 MOCK_METHOD1(EnableBuiltInAEC, int(bool enable)); 238 MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool()); 239 MOCK_METHOD1(EnableBuiltInAGC, int(bool enable)); 240 MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool()); 241 MOCK_METHOD1(EnableBuiltInNS, int(bool enable)); 242 243 // VoENetEqStats 244 MOCK_METHOD2(GetNetworkStatistics, 245 int(int channel, NetworkStatistics& stats)); 246 MOCK_CONST_METHOD2(GetDecodingCallStatistics, 247 int(int channel, AudioDecodingCallStats* stats)); 248 249 // VoENetwork 250 MOCK_METHOD2(RegisterExternalTransport, 251 int(int channel, Transport& transport)); 252 MOCK_METHOD1(DeRegisterExternalTransport, int(int channel)); 253 MOCK_METHOD3(ReceivedRTPPacket, 254 int(int channel, const void* data, size_t length)); 255 MOCK_METHOD4(ReceivedRTPPacket, 256 int(int channel, 257 const void* data, 258 size_t length, 259 const PacketTime& packet_time)); 260 MOCK_METHOD3(ReceivedRTCPPacket, 261 int(int channel, const void* data, size_t length)); 262 263 // VoERTP_RTCP 264 MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc)); 265 MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc)); 266 MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc)); 267 MOCK_METHOD3(SetSendAudioLevelIndicationStatus, 268 int(int channel, bool enable, unsigned char id)); 269 MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus, 270 int(int channel, bool enable, unsigned char id)); 271 MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus, 272 int(int channel, bool enable, unsigned char id)); 273 MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus, 274 int(int channel, bool enable, unsigned char id)); 275 MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable)); 276 MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled)); 277 MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256])); 278 MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256])); 279 MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256])); 280 MOCK_METHOD7(GetRemoteRTCPData, 281 int(int channel, 282 unsigned int& NTPHigh, 283 unsigned int& NTPLow, 284 unsigned int& timestamp, 285 unsigned int& playoutTimestamp, 286 unsigned int* jitter, 287 unsigned short* fractionLost)); 288 MOCK_METHOD4(GetRTPStatistics, 289 int(int channel, 290 unsigned int& averageJitterMs, 291 unsigned int& maxJitterMs, 292 unsigned int& discardedPackets)); 293 MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats)); 294 MOCK_METHOD2(GetRemoteRTCPReportBlocks, 295 int(int channel, std::vector<ReportBlock>* receive_blocks)); 296 MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype)); 297 MOCK_METHOD3(GetREDStatus, 298 int(int channel, bool& enable, int& redPayloadtype)); 299 MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets)); 300 301 // VoEVideoSync 302 MOCK_METHOD1(GetPlayoutBufferSize, int(int& buffer_ms)); 303 MOCK_METHOD2(SetMinimumPlayoutDelay, int(int channel, int delay_ms)); 304 MOCK_METHOD3(GetDelayEstimate, 305 int(int channel, 306 int* jitter_buffer_delay_ms, 307 int* playout_buffer_delay_ms)); 308 MOCK_CONST_METHOD1(GetLeastRequiredDelayMs, int(int channel)); 309 MOCK_METHOD2(SetInitTimestamp, int(int channel, unsigned int timestamp)); 310 MOCK_METHOD2(SetInitSequenceNumber, int(int channel, short sequenceNumber)); 311 MOCK_METHOD2(GetPlayoutTimestamp, int(int channel, unsigned int& timestamp)); 312 MOCK_METHOD3(GetRtpRtcp, 313 int(int channel, 314 RtpRtcp** rtpRtcpModule, 315 RtpReceiver** rtp_receiver)); 316 317 // VoEVolumeControl 318 MOCK_METHOD1(SetSpeakerVolume, int(unsigned int volume)); 319 MOCK_METHOD1(GetSpeakerVolume, int(unsigned int& volume)); 320 MOCK_METHOD1(SetMicVolume, int(unsigned int volume)); 321 MOCK_METHOD1(GetMicVolume, int(unsigned int& volume)); 322 MOCK_METHOD2(SetInputMute, int(int channel, bool enable)); 323 MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled)); 324 MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level)); 325 MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level)); 326 MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level)); 327 MOCK_METHOD2(GetSpeechOutputLevelFullRange, 328 int(int channel, unsigned& level)); 329 MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling)); 330 MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling)); 331 MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right)); 332 MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right)); 333 }; 334 } // namespace test 335 } // namespace webrtc 336 337 #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ 338