Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 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 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 16 | #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" |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 19 | #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 20 | #include "webrtc/test/gmock.h" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 21 | #include "webrtc/test/mock_voe_channel_proxy.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 22 | #include "webrtc/voice_engine/voice_engine_impl.h" |
| 23 | |
| 24 | namespace webrtc { |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 25 | namespace voe { |
| 26 | class TransmitMixer; |
| 27 | } // namespace voe |
| 28 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 29 | namespace 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(). |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 33 | class MockVoiceEngine : public VoiceEngineImpl { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 34 | public: |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 35 | // 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. |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 39 | MockVoiceEngine( |
| 40 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr) |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 41 | : decoder_factory_(decoder_factory) { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 42 | // Increase ref count so this object isn't automatically deleted whenever |
| 43 | // interfaces are Release():d. |
| 44 | ++_ref_count; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 45 | // We add this default behavior to make the mock easier to use in tests. It |
| 46 | // will create a NiceMock of a voe::ChannelProxy. |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 47 | // TODO(ossu): As long as AudioReceiveStream is implemented as a wrapper |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 48 | // around Channel, we need to make sure ChannelProxy returns the same |
| 49 | // decoder factory as the one passed in when creating an AudioReceiveStream. |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 50 | ON_CALL(*this, ChannelProxyFactory(testing::_)) |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 51 | .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_)); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 56 | EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_)) |
| 57 | .WillRepeatedly(testing::Invoke( |
| 58 | [](const std::map<int, SdpAudioFormat>& codecs) { |
| 59 | EXPECT_THAT(codecs, testing::IsEmpty()); |
| 60 | })); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 61 | EXPECT_CALL(*proxy, GetRtpRtcp(testing::_, testing::_)) |
| 62 | .WillRepeatedly( |
| 63 | testing::SetArgPointee<0>(GetMockRtpRtcp(channel_id))); |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 64 | return proxy; |
| 65 | })); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 66 | |
tommi | 8eb0751 | 2017-03-13 08:23:35 -0700 | [diff] [blame] | 67 | ON_CALL(mock_audio_device_, TimeUntilNextProcess()) |
| 68 | .WillByDefault(testing::Return(1000)); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 69 | 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 Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 75 | } |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 76 | virtual ~MockVoiceEngine() /* override */ { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 77 | // Decrease ref count before base class d-tor is called; otherwise it will |
| 78 | // trigger an assertion. |
| 79 | --_ref_count; |
| 80 | } |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 81 | |
| 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 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 90 | // Allows injecting a ChannelProxy factory. |
| 91 | MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); |
| 92 | |
| 93 | // VoiceEngineImpl |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 94 | virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 95 | int channel_id) /* override */ { |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 96 | return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 97 | } |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 98 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 99 | // VoEBase |
| 100 | MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer)); |
| 101 | MOCK_METHOD0(DeRegisterVoiceEngineObserver, int()); |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 102 | MOCK_METHOD3( |
| 103 | Init, |
| 104 | int(AudioDeviceModule* external_adm, |
| 105 | AudioProcessing* audioproc, |
| 106 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 107 | MOCK_METHOD0(audio_processing, AudioProcessing*()); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 108 | MOCK_METHOD0(audio_device_module, AudioDeviceModule*()); |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 109 | MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*()); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 110 | MOCK_METHOD0(Terminate, int()); |
| 111 | MOCK_METHOD0(CreateChannel, int()); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 112 | MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 113 | 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 Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 146 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 147 | // 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 Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 196 | // 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 | |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 248 | 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_; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 256 | |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 257 | std::map<int, std::unique_ptr<MockRtpRtcp>> mock_rtp_rtcps_; |
| 258 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 259 | MockAudioDeviceModule mock_audio_device_; |
| 260 | MockAudioProcessing mock_audio_processing_; |
| 261 | MockAudioTransport mock_audio_transport_; |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 262 | }; |
| 263 | } // namespace test |
| 264 | } // namespace webrtc |
| 265 | |
| 266 | #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |