blob: 1c087262608d06b76baadf6c82a8933d4335149a [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
Per Åhgren0aefbf02019-08-23 21:29:17 +020016#include "modules/audio_processing/audio_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_processing/include/aec_dump.h"
18#include "modules/audio_processing/include/audio_processing.h"
Ivo Creusen56d46092017-11-24 17:29:59 +010019#include "modules/audio_processing/include/audio_processing_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "test/gmock.h"
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000021
22namespace webrtc {
23
solenberg059fb442016-10-26 05:12:24 -070024namespace test {
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000025class MockGainControl : public GainControl {
26 public:
solenberg059fb442016-10-26 05:12:24 -070027 virtual ~MockGainControl() {}
28 MOCK_METHOD1(Enable, int(bool enable));
29 MOCK_CONST_METHOD0(is_enabled, bool());
30 MOCK_METHOD1(set_stream_analog_level, int(int level));
Sam Zackrissonf0d1c032019-03-27 13:28:08 +010031 MOCK_CONST_METHOD0(stream_analog_level, int());
solenberg059fb442016-10-26 05:12:24 -070032 MOCK_METHOD1(set_mode, int(Mode mode));
33 MOCK_CONST_METHOD0(mode, Mode());
34 MOCK_METHOD1(set_target_level_dbfs, int(int level));
35 MOCK_CONST_METHOD0(target_level_dbfs, int());
36 MOCK_METHOD1(set_compression_gain_db, int(int gain));
37 MOCK_CONST_METHOD0(compression_gain_db, int());
38 MOCK_METHOD1(enable_limiter, int(bool enable));
39 MOCK_CONST_METHOD0(is_limiter_enabled, bool());
40 MOCK_METHOD2(set_analog_level_limits, int(int minimum, int maximum));
41 MOCK_CONST_METHOD0(analog_level_minimum, int());
42 MOCK_CONST_METHOD0(analog_level_maximum, int());
43 MOCK_CONST_METHOD0(stream_is_saturated, bool());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000044};
45
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000046class MockLevelEstimator : public LevelEstimator {
47 public:
solenberg059fb442016-10-26 05:12:24 -070048 virtual ~MockLevelEstimator() {}
49 MOCK_METHOD1(Enable, int(bool enable));
50 MOCK_CONST_METHOD0(is_enabled, bool());
51 MOCK_METHOD0(RMS, int());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000052};
53
54class MockNoiseSuppression : public NoiseSuppression {
55 public:
solenberg059fb442016-10-26 05:12:24 -070056 virtual ~MockNoiseSuppression() {}
57 MOCK_METHOD1(Enable, int(bool enable));
58 MOCK_CONST_METHOD0(is_enabled, bool());
59 MOCK_METHOD1(set_level, int(Level level));
60 MOCK_CONST_METHOD0(level, Level());
61 MOCK_CONST_METHOD0(speech_probability, float());
Alejandro Luebsfa639f02016-02-09 11:24:32 -080062 MOCK_METHOD0(NoiseEstimate, std::vector<float>());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000063};
64
Alex Loiko5825aa62017-12-18 16:02:40 +010065class MockCustomProcessing : public CustomProcessing {
Sam Zackrisson0beac582017-09-25 12:04:02 +020066 public:
Alex Loiko5825aa62017-12-18 16:02:40 +010067 virtual ~MockCustomProcessing() {}
Sam Zackrisson0beac582017-09-25 12:04:02 +020068 MOCK_METHOD2(Initialize, void(int sample_rate_hz, int num_channels));
69 MOCK_METHOD1(Process, void(AudioBuffer* audio));
Alex Loiko73ec0192018-05-15 10:52:28 +020070 MOCK_METHOD1(SetRuntimeSetting,
71 void(AudioProcessing::RuntimeSetting setting));
Sam Zackrisson0beac582017-09-25 12:04:02 +020072 MOCK_CONST_METHOD0(ToString, std::string());
73};
74
Valeriia Nemychnikovaf06eb572018-08-29 10:37:09 +020075class MockCustomAudioAnalyzer : public CustomAudioAnalyzer {
76 public:
77 virtual ~MockCustomAudioAnalyzer() {}
78 MOCK_METHOD2(Initialize, void(int sample_rate_hz, int num_channels));
79 MOCK_METHOD1(Analyze, void(const AudioBuffer* audio));
80 MOCK_CONST_METHOD0(ToString, std::string());
81};
82
Gustaf Ullberg002ef282017-10-12 15:13:17 +020083class MockEchoControl : public EchoControl {
84 public:
85 virtual ~MockEchoControl() {}
86 MOCK_METHOD1(AnalyzeRender, void(AudioBuffer* render));
87 MOCK_METHOD1(AnalyzeCapture, void(AudioBuffer* capture));
88 MOCK_METHOD2(ProcessCapture,
89 void(AudioBuffer* capture, bool echo_path_change));
Gustaf Ullberg332150d2017-11-22 14:17:39 +010090 MOCK_CONST_METHOD0(GetMetrics, Metrics());
Per Åhgrend0fa8202018-04-18 09:35:13 +020091 MOCK_METHOD1(SetAudioBufferDelay, void(size_t delay_ms));
Gustaf Ullberg002ef282017-10-12 15:13:17 +020092};
93
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +000094class MockVoiceDetection : public VoiceDetection {
95 public:
solenberg059fb442016-10-26 05:12:24 -070096 virtual ~MockVoiceDetection() {}
97 MOCK_METHOD1(Enable, int(bool enable));
98 MOCK_CONST_METHOD0(is_enabled, bool());
99 MOCK_CONST_METHOD0(stream_has_voice, bool());
100 MOCK_METHOD1(set_stream_has_voice, int(bool has_voice));
101 MOCK_METHOD1(set_likelihood, int(Likelihood likelihood));
102 MOCK_CONST_METHOD0(likelihood, Likelihood());
103 MOCK_METHOD1(set_frame_size_ms, int(int size));
104 MOCK_CONST_METHOD0(frame_size_ms, int());
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000105};
106
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200107class MockAudioProcessing : public ::testing::NiceMock<AudioProcessing> {
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000108 public:
109 MockAudioProcessing()
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200110 : gain_control_(new ::testing::NiceMock<MockGainControl>()),
111 level_estimator_(new ::testing::NiceMock<MockLevelEstimator>()),
112 noise_suppression_(new ::testing::NiceMock<MockNoiseSuppression>()),
113 voice_detection_(new ::testing::NiceMock<MockVoiceDetection>()) {}
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000114
solenberg059fb442016-10-26 05:12:24 -0700115 virtual ~MockAudioProcessing() {}
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000116
solenberg059fb442016-10-26 05:12:24 -0700117 MOCK_METHOD0(Initialize, int());
Yves Gerey665174f2018-06-19 15:03:05 +0200118 MOCK_METHOD6(Initialize,
119 int(int capture_input_sample_rate_hz,
120 int capture_output_sample_rate_hz,
121 int render_sample_rate_hz,
122 ChannelLayout capture_input_layout,
123 ChannelLayout capture_output_layout,
124 ChannelLayout render_input_layout));
solenberg059fb442016-10-26 05:12:24 -0700125 MOCK_METHOD1(Initialize, int(const ProcessingConfig& processing_config));
peah88ac8532016-09-12 16:47:25 -0700126 MOCK_METHOD1(ApplyConfig, void(const Config& config));
127 MOCK_METHOD1(SetExtraOptions, void(const webrtc::Config& config));
solenberg059fb442016-10-26 05:12:24 -0700128 MOCK_CONST_METHOD0(proc_sample_rate_hz, int());
129 MOCK_CONST_METHOD0(proc_split_sample_rate_hz, int());
130 MOCK_CONST_METHOD0(num_input_channels, size_t());
131 MOCK_CONST_METHOD0(num_proc_channels, size_t());
132 MOCK_CONST_METHOD0(num_output_channels, size_t());
133 MOCK_CONST_METHOD0(num_reverse_channels, size_t());
134 MOCK_METHOD1(set_output_will_be_muted, void(bool muted));
Alessio Bazzicac054e782018-04-16 12:10:09 +0200135 MOCK_METHOD1(SetRuntimeSetting, void(RuntimeSetting setting));
solenberg059fb442016-10-26 05:12:24 -0700136 MOCK_METHOD1(ProcessStream, int(AudioFrame* frame));
Yves Gerey665174f2018-06-19 15:03:05 +0200137 MOCK_METHOD7(ProcessStream,
138 int(const float* const* src,
139 size_t samples_per_channel,
140 int input_sample_rate_hz,
141 ChannelLayout input_layout,
142 int output_sample_rate_hz,
143 ChannelLayout output_layout,
144 float* const* dest));
145 MOCK_METHOD4(ProcessStream,
146 int(const float* const* src,
147 const StreamConfig& input_config,
148 const StreamConfig& output_config,
149 float* const* dest));
ekmeyerson60d9b332015-08-14 10:35:55 -0700150 MOCK_METHOD1(ProcessReverseStream, int(AudioFrame* frame));
Yves Gerey665174f2018-06-19 15:03:05 +0200151 MOCK_METHOD4(AnalyzeReverseStream,
152 int(const float* const* data,
153 size_t samples_per_channel,
154 int sample_rate_hz,
155 ChannelLayout layout));
156 MOCK_METHOD4(ProcessReverseStream,
157 int(const float* const* src,
158 const StreamConfig& input_config,
159 const StreamConfig& output_config,
160 float* const* dest));
solenberg059fb442016-10-26 05:12:24 -0700161 MOCK_METHOD1(set_stream_delay_ms, int(int delay));
162 MOCK_CONST_METHOD0(stream_delay_ms, int());
163 MOCK_CONST_METHOD0(was_stream_delay_set, bool());
164 MOCK_METHOD1(set_stream_key_pressed, void(bool key_pressed));
165 MOCK_METHOD1(set_delay_offset_ms, void(int offset));
166 MOCK_CONST_METHOD0(delay_offset_ms, int());
Sam Zackrissonf0d1c032019-03-27 13:28:08 +0100167 MOCK_METHOD1(set_stream_analog_level, void(int));
168 MOCK_CONST_METHOD0(recommended_stream_analog_level, int());
aleloi868f32f2017-05-23 07:20:05 -0700169
170 virtual void AttachAecDump(std::unique_ptr<AecDump> aec_dump) {}
171 MOCK_METHOD0(DetachAecDump, void());
172
Sam Zackrisson4d364492018-03-02 16:03:21 +0100173 virtual void AttachPlayoutAudioGenerator(
174 std::unique_ptr<AudioGenerator> audio_generator) {}
175 MOCK_METHOD0(DetachPlayoutAudioGenerator, void());
176
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200177 MOCK_METHOD0(UpdateHistogramsOnCallEnd, void());
Ivo Creusen56d46092017-11-24 17:29:59 +0100178 MOCK_CONST_METHOD1(GetStatistics, AudioProcessingStats(bool));
Yves Gerey665174f2018-06-19 15:03:05 +0200179 virtual MockGainControl* gain_control() const { return gain_control_.get(); }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000180 virtual MockLevelEstimator* level_estimator() const {
181 return level_estimator_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000182 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000183 virtual MockNoiseSuppression* noise_suppression() const {
184 return noise_suppression_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000185 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000186 virtual MockVoiceDetection* voice_detection() const {
187 return voice_detection_.get();
andrew@webrtc.org17e40642014-03-04 20:58:13 +0000188 }
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000189
henrik.lundinadf06352017-04-05 05:48:24 -0700190 MOCK_CONST_METHOD0(GetConfig, AudioProcessing::Config());
191
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000192 private:
kwiberg88788ad2016-02-19 07:04:49 -0800193 std::unique_ptr<MockGainControl> gain_control_;
kwiberg88788ad2016-02-19 07:04:49 -0800194 std::unique_ptr<MockLevelEstimator> level_estimator_;
195 std::unique_ptr<MockNoiseSuppression> noise_suppression_;
196 std::unique_ptr<MockVoiceDetection> voice_detection_;
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000197};
198
solenberg059fb442016-10-26 05:12:24 -0700199} // namespace test
andrew@webrtc.orgc83a00a2013-03-25 21:20:38 +0000200} // namespace webrtc
201
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200202#endif // MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_