blob: 2d4938842548615cb9d7558cb1bf666e30db11e7 [file] [log] [blame]
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +00001/*
2 * Copyright (c) 2013 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_
12#define MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000013
kwiberg88788ad2016-02-19 07:04:49 -080014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/include/aec_dump.h"
17#include "modules/audio_processing/include/audio_processing.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010018#include "modules/audio_processing/include/audio_processing_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "test/gmock.h"
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000020
21namespace webrtc {
22
solenberg059fb442016-10-26 05:12:24 -070023namespace test {
24
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000025class MockEchoCancellation : public EchoCancellation {
26 public:
solenberg059fb442016-10-26 05:12:24 -070027 virtual ~MockEchoCancellation() {}
28 MOCK_METHOD1(Enable, int(bool enable));
29 MOCK_CONST_METHOD0(is_enabled, bool());
30 MOCK_METHOD1(enable_drift_compensation, int(bool enable));
31 MOCK_CONST_METHOD0(is_drift_compensation_enabled, bool());
32 MOCK_METHOD1(set_stream_drift_samples, void(int drift));
33 MOCK_CONST_METHOD0(stream_drift_samples, int());
34 MOCK_METHOD1(set_suppression_level, int(SuppressionLevel level));
35 MOCK_CONST_METHOD0(suppression_level, SuppressionLevel());
36 MOCK_CONST_METHOD0(stream_has_echo, bool());
37 MOCK_METHOD1(enable_metrics, int(bool enable));
38 MOCK_CONST_METHOD0(are_metrics_enabled, bool());
39 MOCK_METHOD1(GetMetrics, int(Metrics* metrics));
40 MOCK_METHOD1(enable_delay_logging, int(bool enable));
41 MOCK_CONST_METHOD0(is_delay_logging_enabled, bool());
42 MOCK_METHOD2(GetDelayMetrics, int(int* median, int* std));
43 MOCK_METHOD3(GetDelayMetrics, int(int* median, int* std,
44 float* fraction_poor_delays));
45 MOCK_CONST_METHOD0(aec_core, struct AecCore*());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000046};
47
48class MockEchoControlMobile : public EchoControlMobile {
49 public:
solenberg059fb442016-10-26 05:12:24 -070050 virtual ~MockEchoControlMobile() {}
51 MOCK_METHOD1(Enable, int(bool enable));
52 MOCK_CONST_METHOD0(is_enabled, bool());
53 MOCK_METHOD1(set_routing_mode, int(RoutingMode mode));
54 MOCK_CONST_METHOD0(routing_mode, RoutingMode());
55 MOCK_METHOD1(enable_comfort_noise, int(bool enable));
56 MOCK_CONST_METHOD0(is_comfort_noise_enabled, bool());
57 MOCK_METHOD2(SetEchoPath, int(const void* echo_path, size_t size_bytes));
58 MOCK_CONST_METHOD2(GetEchoPath, int(void* echo_path, size_t size_bytes));
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000059};
60
61class MockGainControl : public GainControl {
62 public:
solenberg059fb442016-10-26 05:12:24 -070063 virtual ~MockGainControl() {}
64 MOCK_METHOD1(Enable, int(bool enable));
65 MOCK_CONST_METHOD0(is_enabled, bool());
66 MOCK_METHOD1(set_stream_analog_level, int(int level));
67 MOCK_METHOD0(stream_analog_level, int());
68 MOCK_METHOD1(set_mode, int(Mode mode));
69 MOCK_CONST_METHOD0(mode, Mode());
70 MOCK_METHOD1(set_target_level_dbfs, int(int level));
71 MOCK_CONST_METHOD0(target_level_dbfs, int());
72 MOCK_METHOD1(set_compression_gain_db, int(int gain));
73 MOCK_CONST_METHOD0(compression_gain_db, int());
74 MOCK_METHOD1(enable_limiter, int(bool enable));
75 MOCK_CONST_METHOD0(is_limiter_enabled, bool());
76 MOCK_METHOD2(set_analog_level_limits, int(int minimum, int maximum));
77 MOCK_CONST_METHOD0(analog_level_minimum, int());
78 MOCK_CONST_METHOD0(analog_level_maximum, int());
79 MOCK_CONST_METHOD0(stream_is_saturated, bool());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000080};
81
82class MockHighPassFilter : public HighPassFilter {
83 public:
solenberg059fb442016-10-26 05:12:24 -070084 virtual ~MockHighPassFilter() {}
85 MOCK_METHOD1(Enable, int(bool enable));
86 MOCK_CONST_METHOD0(is_enabled, bool());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000087};
88
89class MockLevelEstimator : public LevelEstimator {
90 public:
solenberg059fb442016-10-26 05:12:24 -070091 virtual ~MockLevelEstimator() {}
92 MOCK_METHOD1(Enable, int(bool enable));
93 MOCK_CONST_METHOD0(is_enabled, bool());
94 MOCK_METHOD0(RMS, int());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000095};
96
97class MockNoiseSuppression : public NoiseSuppression {
98 public:
solenberg059fb442016-10-26 05:12:24 -070099 virtual ~MockNoiseSuppression() {}
100 MOCK_METHOD1(Enable, int(bool enable));
101 MOCK_CONST_METHOD0(is_enabled, bool());
102 MOCK_METHOD1(set_level, int(Level level));
103 MOCK_CONST_METHOD0(level, Level());
104 MOCK_CONST_METHOD0(speech_probability, float());
Alejandro Luebsfa639f02016-02-09 11:24:32 -0800105 MOCK_METHOD0(NoiseEstimate, std::vector<float>());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000106};
107
Alex Loiko5825aa62017-12-18 16:02:40 +0100108class MockCustomProcessing : public CustomProcessing {
Sam Zackrisson0beac582017-09-25 12:04:02 +0200109 public:
Alex Loiko5825aa62017-12-18 16:02:40 +0100110 virtual ~MockCustomProcessing() {}
Sam Zackrisson0beac582017-09-25 12:04:02 +0200111 MOCK_METHOD2(Initialize, void(int sample_rate_hz, int num_channels));
112 MOCK_METHOD1(Process, void(AudioBuffer* audio));
113 MOCK_CONST_METHOD0(ToString, std::string());
114};
115
Gustaf Ullberg002ef282017-10-12 15:13:17 +0200116class MockEchoControl : public EchoControl {
117 public:
118 virtual ~MockEchoControl() {}
119 MOCK_METHOD1(AnalyzeRender, void(AudioBuffer* render));
120 MOCK_METHOD1(AnalyzeCapture, void(AudioBuffer* capture));
121 MOCK_METHOD2(ProcessCapture,
122 void(AudioBuffer* capture, bool echo_path_change));
Gustaf Ullberg332150d2017-11-22 14:17:39 +0100123 MOCK_CONST_METHOD0(GetMetrics, Metrics());
Gustaf Ullberg002ef282017-10-12 15:13:17 +0200124};
125
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000126class MockVoiceDetection : public VoiceDetection {
127 public:
solenberg059fb442016-10-26 05:12:24 -0700128 virtual ~MockVoiceDetection() {}
129 MOCK_METHOD1(Enable, int(bool enable));
130 MOCK_CONST_METHOD0(is_enabled, bool());
131 MOCK_CONST_METHOD0(stream_has_voice, bool());
132 MOCK_METHOD1(set_stream_has_voice, int(bool has_voice));
133 MOCK_METHOD1(set_likelihood, int(Likelihood likelihood));
134 MOCK_CONST_METHOD0(likelihood, Likelihood());
135 MOCK_METHOD1(set_frame_size_ms, int(int size));
136 MOCK_CONST_METHOD0(frame_size_ms, int());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000137};
138
Sebastian Jansson41f16be2018-02-22 11:09:56 +0100139class MockAudioProcessing : public testing::NiceMock<AudioProcessing> {
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000140 public:
141 MockAudioProcessing()
solenberg059fb442016-10-26 05:12:24 -0700142 : echo_cancellation_(new testing::NiceMock<MockEchoCancellation>()),
143 echo_control_mobile_(new testing::NiceMock<MockEchoControlMobile>()),
144 gain_control_(new testing::NiceMock<MockGainControl>()),
145 high_pass_filter_(new testing::NiceMock<MockHighPassFilter>()),
146 level_estimator_(new testing::NiceMock<MockLevelEstimator>()),
147 noise_suppression_(new testing::NiceMock<MockNoiseSuppression>()),
148 voice_detection_(new testing::NiceMock<MockVoiceDetection>()) {
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000149 }
150
solenberg059fb442016-10-26 05:12:24 -0700151 virtual ~MockAudioProcessing() {}
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000152
solenberg059fb442016-10-26 05:12:24 -0700153 MOCK_METHOD0(Initialize, int());
154 MOCK_METHOD6(Initialize, int(int capture_input_sample_rate_hz,
155 int capture_output_sample_rate_hz,
156 int render_sample_rate_hz,
157 ChannelLayout capture_input_layout,
158 ChannelLayout capture_output_layout,
159 ChannelLayout render_input_layout));
160 MOCK_METHOD1(Initialize, int(const ProcessingConfig& processing_config));
peah88ac8532016-09-12 16:47:25 -0700161 MOCK_METHOD1(ApplyConfig, void(const Config& config));
162 MOCK_METHOD1(SetExtraOptions, void(const webrtc::Config& config));
solenberg059fb442016-10-26 05:12:24 -0700163 MOCK_CONST_METHOD0(proc_sample_rate_hz, int());
164 MOCK_CONST_METHOD0(proc_split_sample_rate_hz, int());
165 MOCK_CONST_METHOD0(num_input_channels, size_t());
166 MOCK_CONST_METHOD0(num_proc_channels, size_t());
167 MOCK_CONST_METHOD0(num_output_channels, size_t());
168 MOCK_CONST_METHOD0(num_reverse_channels, size_t());
169 MOCK_METHOD1(set_output_will_be_muted, void(bool muted));
Alessio Bazzicac054e782018-04-16 12:10:09 +0200170 MOCK_METHOD1(SetRuntimeSetting, void(RuntimeSetting setting));
solenberg059fb442016-10-26 05:12:24 -0700171 MOCK_METHOD1(ProcessStream, int(AudioFrame* frame));
172 MOCK_METHOD7(ProcessStream, int(const float* const* src,
173 size_t samples_per_channel,
174 int input_sample_rate_hz,
175 ChannelLayout input_layout,
176 int output_sample_rate_hz,
177 ChannelLayout output_layout,
178 float* const* dest));
179 MOCK_METHOD4(ProcessStream, int(const float* const* src,
180 const StreamConfig& input_config,
181 const StreamConfig& output_config,
182 float* const* dest));
ekmeyerson60d9b332015-08-14 10:35:55 -0700183 MOCK_METHOD1(ProcessReverseStream, int(AudioFrame* frame));
solenberg059fb442016-10-26 05:12:24 -0700184 MOCK_METHOD4(AnalyzeReverseStream, int(const float* const* data,
185 size_t samples_per_channel,
186 int sample_rate_hz,
187 ChannelLayout layout));
188 MOCK_METHOD4(ProcessReverseStream, int(const float* const* src,
189 const StreamConfig& input_config,
190 const StreamConfig& output_config,
191 float* const* dest));
192 MOCK_METHOD1(set_stream_delay_ms, int(int delay));
193 MOCK_CONST_METHOD0(stream_delay_ms, int());
194 MOCK_CONST_METHOD0(was_stream_delay_set, bool());
195 MOCK_METHOD1(set_stream_key_pressed, void(bool key_pressed));
196 MOCK_METHOD1(set_delay_offset_ms, void(int offset));
197 MOCK_CONST_METHOD0(delay_offset_ms, int());
aleloi868f32f2017-05-23 07:20:05 -0700198
199 virtual void AttachAecDump(std::unique_ptr<AecDump> aec_dump) {}
200 MOCK_METHOD0(DetachAecDump, void());
201
Sam Zackrisson4d364492018-03-02 16:03:21 +0100202 virtual void AttachPlayoutAudioGenerator(
203 std::unique_ptr<AudioGenerator> audio_generator) {}
204 MOCK_METHOD0(DetachPlayoutAudioGenerator, void());
205
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200206 MOCK_METHOD0(UpdateHistogramsOnCallEnd, void());
ivoc3e9a5372016-10-28 07:55:33 -0700207 MOCK_CONST_METHOD0(GetStatistics, AudioProcessingStatistics());
Ivo Creusen56d46092017-11-24 17:29:59 +0100208 MOCK_CONST_METHOD1(GetStatistics, AudioProcessingStats(bool));
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000209 virtual MockEchoCancellation* echo_cancellation() const {
210 return echo_cancellation_.get();
211 }
212 virtual MockEchoControlMobile* echo_control_mobile() const {
213 return echo_control_mobile_.get();
214 }
215 virtual MockGainControl* gain_control() const {
216 return gain_control_.get();
217 }
218 virtual MockHighPassFilter* high_pass_filter() const {
219 return high_pass_filter_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000220 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000221 virtual MockLevelEstimator* level_estimator() const {
222 return level_estimator_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000223 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000224 virtual MockNoiseSuppression* noise_suppression() const {
225 return noise_suppression_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000226 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000227 virtual MockVoiceDetection* voice_detection() const {
228 return voice_detection_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000229 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000230
henrik.lundinadf06352017-04-05 05:48:24 -0700231 MOCK_CONST_METHOD0(GetConfig, AudioProcessing::Config());
232
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000233 private:
kwiberg88788ad2016-02-19 07:04:49 -0800234 std::unique_ptr<MockEchoCancellation> echo_cancellation_;
235 std::unique_ptr<MockEchoControlMobile> echo_control_mobile_;
236 std::unique_ptr<MockGainControl> gain_control_;
237 std::unique_ptr<MockHighPassFilter> high_pass_filter_;
238 std::unique_ptr<MockLevelEstimator> level_estimator_;
239 std::unique_ptr<MockNoiseSuppression> noise_suppression_;
240 std::unique_ptr<MockVoiceDetection> voice_detection_;
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000241};
242
solenberg059fb442016-10-26 05:12:24 -0700243} // namespace test
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000244} // namespace webrtc
245
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200246#endif // MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_