summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-03-25 21:20:38 +0000
committerandrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-03-25 21:20:38 +0000
commit13f66d1472df67158e2c9d2fe1d6d6dacc69e936 (patch)
tree4365e1ff994edf36b63f4def51053e90651fec37
parent8826e340dfb6dbbb1a4f63737c554707bdaddfa9 (diff)
downloadwebrtc-13f66d1472df67158e2c9d2fe1d6d6dacc69e936.tar.gz
Add some VoE and AudioProcessing mocks.
Includes a bit of shared helpers in fake_common.h. Review URL: https://webrtc-codereview.appspot.com/1221004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@3722 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r--modules/audio_processing/include/mock_audio_processing.h252
-rw-r--r--test/fake_common.h48
-rw-r--r--typedefs.h13
-rw-r--r--voice_engine/include/mock/fake_voe_external_media.h77
-rw-r--r--voice_engine/include/mock/mock_voe_volume_control.h47
5 files changed, 437 insertions, 0 deletions
diff --git a/modules/audio_processing/include/mock_audio_processing.h b/modules/audio_processing/include/mock_audio_processing.h
new file mode 100644
index 00000000..c0d0a968
--- /dev/null
+++ b/modules/audio_processing/include/mock_audio_processing.h
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_
+#define WEBRTC_MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_
+
+#include "webrtc/modules/audio_processing/include/audio_processing.h"
+#include "webrtc/system_wrappers/interface/scoped_ptr.h"
+
+namespace webrtc {
+
+class MockEchoCancellation : public EchoCancellation {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_METHOD1(enable_drift_compensation,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_drift_compensation_enabled,
+ bool());
+ MOCK_METHOD1(set_device_sample_rate_hz,
+ int(int rate));
+ MOCK_CONST_METHOD0(device_sample_rate_hz,
+ int());
+ MOCK_METHOD1(set_stream_drift_samples,
+ void(int drift));
+ MOCK_CONST_METHOD0(stream_drift_samples,
+ int());
+ MOCK_METHOD1(set_suppression_level,
+ int(SuppressionLevel level));
+ MOCK_CONST_METHOD0(suppression_level,
+ SuppressionLevel());
+ MOCK_CONST_METHOD0(stream_has_echo,
+ bool());
+ MOCK_METHOD1(enable_metrics,
+ int(bool enable));
+ MOCK_CONST_METHOD0(are_metrics_enabled,
+ bool());
+ MOCK_METHOD1(GetMetrics,
+ int(Metrics* metrics));
+ MOCK_METHOD1(enable_delay_logging,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_delay_logging_enabled,
+ bool());
+ MOCK_METHOD2(GetDelayMetrics,
+ int(int* median, int* std));
+ MOCK_CONST_METHOD0(aec_core,
+ struct AecCore*());
+};
+
+class MockEchoControlMobile : public EchoControlMobile {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_METHOD1(set_routing_mode,
+ int(RoutingMode mode));
+ MOCK_CONST_METHOD0(routing_mode,
+ RoutingMode());
+ MOCK_METHOD1(enable_comfort_noise,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_comfort_noise_enabled,
+ bool());
+ MOCK_METHOD2(SetEchoPath,
+ int(const void* echo_path, size_t size_bytes));
+ MOCK_CONST_METHOD2(GetEchoPath,
+ int(void* echo_path, size_t size_bytes));
+};
+
+class MockGainControl : public GainControl {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_METHOD1(set_stream_analog_level,
+ int(int level));
+ MOCK_METHOD0(stream_analog_level,
+ int());
+ MOCK_METHOD1(set_mode,
+ int(Mode mode));
+ MOCK_CONST_METHOD0(mode,
+ Mode());
+ MOCK_METHOD1(set_target_level_dbfs,
+ int(int level));
+ MOCK_CONST_METHOD0(target_level_dbfs,
+ int());
+ MOCK_METHOD1(set_compression_gain_db,
+ int(int gain));
+ MOCK_CONST_METHOD0(compression_gain_db,
+ int());
+ MOCK_METHOD1(enable_limiter,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_limiter_enabled,
+ bool());
+ MOCK_METHOD2(set_analog_level_limits,
+ int(int minimum, int maximum));
+ MOCK_CONST_METHOD0(analog_level_minimum,
+ int());
+ MOCK_CONST_METHOD0(analog_level_maximum,
+ int());
+ MOCK_CONST_METHOD0(stream_is_saturated,
+ bool());
+};
+
+class MockHighPassFilter : public HighPassFilter {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+};
+
+class MockLevelEstimator : public LevelEstimator {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_METHOD0(RMS,
+ int());
+};
+
+class MockNoiseSuppression : public NoiseSuppression {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_METHOD1(set_level,
+ int(Level level));
+ MOCK_CONST_METHOD0(level,
+ Level());
+ MOCK_CONST_METHOD0(speech_probability,
+ float());
+};
+
+class MockVoiceDetection : public VoiceDetection {
+ public:
+ MOCK_METHOD1(Enable,
+ int(bool enable));
+ MOCK_CONST_METHOD0(is_enabled,
+ bool());
+ MOCK_CONST_METHOD0(stream_has_voice,
+ bool());
+ MOCK_METHOD1(set_stream_has_voice,
+ int(bool has_voice));
+ MOCK_METHOD1(set_likelihood,
+ int(Likelihood likelihood));
+ MOCK_CONST_METHOD0(likelihood,
+ Likelihood());
+ MOCK_METHOD1(set_frame_size_ms,
+ int(int size));
+ MOCK_CONST_METHOD0(frame_size_ms,
+ int());
+};
+
+class MockAudioProcessing : public AudioProcessing {
+ public:
+ MockAudioProcessing()
+ : echo_cancellation_(new MockEchoCancellation),
+ echo_control_mobile_(new MockEchoControlMobile),
+ gain_control_(new MockGainControl),
+ high_pass_filter_(new MockHighPassFilter),
+ level_estimator_(new MockLevelEstimator),
+ noise_suppression_(new MockNoiseSuppression),
+ voice_detection_(new MockVoiceDetection) {
+ }
+
+ virtual ~MockAudioProcessing() {
+ }
+
+ MOCK_METHOD0(Initialize,
+ int());
+ MOCK_METHOD1(set_sample_rate_hz,
+ int(int rate));
+ MOCK_CONST_METHOD0(sample_rate_hz,
+ int());
+ MOCK_METHOD2(set_num_channels,
+ int(int input_channels, int output_channels));
+ MOCK_CONST_METHOD0(num_input_channels,
+ int());
+ MOCK_CONST_METHOD0(num_output_channels,
+ int());
+ MOCK_METHOD1(set_num_reverse_channels,
+ int(int channels));
+ MOCK_CONST_METHOD0(num_reverse_channels,
+ int());
+ MOCK_METHOD1(ProcessStream,
+ int(AudioFrame* frame));
+ MOCK_METHOD1(AnalyzeReverseStream,
+ int(AudioFrame* frame));
+ MOCK_METHOD1(set_stream_delay_ms,
+ int(int delay));
+ MOCK_CONST_METHOD0(stream_delay_ms,
+ int());
+ MOCK_METHOD1(set_delay_offset_ms,
+ void(int offset));
+ MOCK_CONST_METHOD0(delay_offset_ms,
+ int());
+ MOCK_METHOD1(StartDebugRecording,
+ int(const char filename[kMaxFilenameSize]));
+ MOCK_METHOD0(StopDebugRecording,
+ int());
+ virtual MockEchoCancellation* echo_cancellation() const {
+ return echo_cancellation_.get();
+ }
+ virtual MockEchoControlMobile* echo_control_mobile() const {
+ return echo_control_mobile_.get();
+ }
+ virtual MockGainControl* gain_control() const {
+ return gain_control_.get();
+ }
+ virtual MockHighPassFilter* high_pass_filter() const {
+ return high_pass_filter_.get();
+ };
+ virtual MockLevelEstimator* level_estimator() const {
+ return level_estimator_.get();
+ };
+ virtual MockNoiseSuppression* noise_suppression() const {
+ return noise_suppression_.get();
+ };
+ virtual MockVoiceDetection* voice_detection() const {
+ return voice_detection_.get();
+ };
+ MOCK_METHOD0(TimeUntilNextProcess,
+ WebRtc_Word32());
+ MOCK_METHOD0(Process,
+ WebRtc_Word32());
+
+ private:
+ scoped_ptr<MockEchoCancellation> echo_cancellation_;
+ scoped_ptr<MockEchoControlMobile> echo_control_mobile_;
+ scoped_ptr<MockGainControl> gain_control_;
+ scoped_ptr<MockHighPassFilter> high_pass_filter_;
+ scoped_ptr<MockLevelEstimator> level_estimator_;
+ scoped_ptr<MockNoiseSuppression> noise_suppression_;
+ scoped_ptr<MockVoiceDetection> voice_detection_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_INCLUDE_MOCK_AUDIO_PROCESSING_H_
diff --git a/test/fake_common.h b/test/fake_common.h
new file mode 100644
index 00000000..a0748085
--- /dev/null
+++ b/test/fake_common.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_TEST_FAKE_COMMON_H_
+#define WEBRTC_TEST_FAKE_COMMON_H_
+
+// Borrowed from libjingle's talk/media/webrtc/fakewebrtccommon.h.
+
+#include "webrtc/typedefs.h"
+
+#define WEBRTC_STUB(method, args) \
+ virtual int method args OVERRIDE { return 0; }
+
+#define WEBRTC_STUB_CONST(method, args) \
+ virtual int method args const OVERRIDE { return 0; }
+
+#define WEBRTC_BOOL_STUB(method, args) \
+ virtual bool method args OVERRIDE { return true; }
+
+#define WEBRTC_VOID_STUB(method, args) \
+ virtual void method args OVERRIDE {}
+
+#define WEBRTC_FUNC(method, args) \
+ virtual int method args OVERRIDE
+
+#define WEBRTC_FUNC_CONST(method, args) \
+ virtual int method args const OVERRIDE
+
+#define WEBRTC_BOOL_FUNC(method, args) \
+ virtual bool method args OVERRIDE
+
+#define WEBRTC_VOID_FUNC(method, args) \
+ virtual void method args OVERRIDE
+
+#define WEBRTC_CHECK_CHANNEL(channel) \
+ if (channels_.find(channel) == channels_.end()) return -1;
+
+#define WEBRTC_ASSERT_CHANNEL(channel) \
+ ASSERT(channels_.find(channel) != channels_.end());
+
+#endif // WEBRTC_TEST_FAKE_COMMON_H_
diff --git a/typedefs.h b/typedefs.h
index d6d40155..b056ab38 100644
--- a/typedefs.h
+++ b/typedefs.h
@@ -90,4 +90,17 @@ typedef uint16_t WebRtc_UWord16;
typedef uint32_t WebRtc_UWord32;
typedef uint64_t WebRtc_UWord64;
+// Borrowed from Chromium's base/compiler_specific.h.
+// Annotate a virtual method indicating it must be overriding a virtual
+// method in the parent class.
+// Use like:
+// virtual void foo() OVERRIDE;
+#if defined(_MSC_VER)
+#define OVERRIDE override
+#elif defined(__clang__)
+#define OVERRIDE override
+#else
+#define OVERRIDE
+#endif
+
#endif // WEBRTC_TYPEDEFS_H_
diff --git a/voice_engine/include/mock/fake_voe_external_media.h b/voice_engine/include/mock/fake_voe_external_media.h
new file mode 100644
index 00000000..8b608ec2
--- /dev/null
+++ b/voice_engine/include/mock/fake_voe_external_media.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
+#define WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
+
+#include <map>
+
+#include "webrtc/test/fake_common.h"
+#include "webrtc/system_wrappers/interface/scoped_ptr.h"
+#include "webrtc/voice_engine/include/voe_external_media.h"
+
+namespace webrtc {
+
+class FakeVoEExternalMedia : public VoEExternalMedia {
+ public:
+ FakeVoEExternalMedia() {}
+ virtual ~FakeVoEExternalMedia() {}
+
+ WEBRTC_STUB(Release, ());
+ WEBRTC_FUNC(RegisterExternalMediaProcessing,
+ (int channel, ProcessingTypes type, VoEMediaProcess& processObject)) {
+ callback_map_[type] = &processObject;
+ return 0;
+ }
+ WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
+ (int channel, ProcessingTypes type)) {
+ callback_map_.erase(type);
+ return 0;
+ }
+ WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
+ WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
+ WEBRTC_STUB(ExternalRecordingInsertData,
+ (const WebRtc_Word16 speechData10ms[], int lengthSamples,
+ int samplingFreqHz, int current_delay_ms));
+ WEBRTC_STUB(ExternalPlayoutGetData,
+ (WebRtc_Word16 speechData10ms[], int samplingFreqHz,
+ int current_delay_ms, int& lengthSamples));
+ WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
+ AudioFrame* frame));
+ WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
+
+ // Use this to trigger the Process() callback to a registered media processor.
+ // If |audio| is NULL, a zero array of the correct length will be forwarded.
+ void CallProcess(ProcessingTypes type, int16_t* audio,
+ int samples_per_channel, int sample_rate_hz,
+ int num_channels) {
+ const int length = samples_per_channel * num_channels;
+ scoped_array<int16_t> data;
+ if (!audio) {
+ data.reset(new int16_t[length]);
+ memset(data.get(), 0, length * sizeof(data[0]));
+ audio = data.get();
+ }
+
+ std::map<ProcessingTypes, VoEMediaProcess*>::const_iterator it =
+ callback_map_.find(type);
+ if (it != callback_map_.end()) {
+ it->second->Process(0, type, audio, samples_per_channel, sample_rate_hz,
+ num_channels == 2 ? true : false);
+ }
+ }
+
+ private:
+ std::map<ProcessingTypes, VoEMediaProcess*> callback_map_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_FAKE_VOE_EXTERNAL_MEDIA_H_
diff --git a/voice_engine/include/mock/mock_voe_volume_control.h b/voice_engine/include/mock/mock_voe_volume_control.h
new file mode 100644
index 00000000..20b09696
--- /dev/null
+++ b/voice_engine/include/mock/mock_voe_volume_control.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_MOCK_VOE_VOLUME_CONTROL_H_
+#define WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_MOCK_VOE_VOLUME_CONTROL_H_
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "webrtc/voice_engine/include/voe_volume_control.h"
+
+namespace webrtc {
+
+class VoiceEngine;
+
+class MockVoEVolumeControl : public VoEVolumeControl {
+ public:
+ MOCK_METHOD0(Release, int());
+ MOCK_METHOD1(SetSpeakerVolume, int(unsigned int volume));
+ MOCK_METHOD1(GetSpeakerVolume, int(unsigned int& volume));
+ MOCK_METHOD1(SetSystemOutputMute, int(bool enable));
+ MOCK_METHOD1(GetSystemOutputMute, int(bool &enabled));
+ MOCK_METHOD1(SetMicVolume, int(unsigned int volume));
+ MOCK_METHOD1(GetMicVolume, int(unsigned int& volume));
+ MOCK_METHOD2(SetInputMute, int(int channel, bool enable));
+ MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled));
+ MOCK_METHOD1(SetSystemInputMute, int(bool enable));
+ MOCK_METHOD1(GetSystemInputMute, int(bool& enabled));
+ MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level));
+ MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level));
+ MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level));
+ MOCK_METHOD2(GetSpeechOutputLevelFullRange,
+ int(int channel, unsigned int& level));
+ MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling));
+ MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling));
+ MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right));
+ MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right));
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_VOICE_ENGINE_INCLUDE_MOCK_MOCK_VOE_VOLUME_CONTROL_H_