From 56e4a05053d6addc7dbbe2b4d07271305fdbea75 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Thu, 27 Feb 2014 22:23:17 +0000 Subject: [PATCH] Remove ProcessingComponent's dependence on AudioProcessingImpl. - Move needed accessors to AudioProcessing. - Inject the crit directly as a dependency. - Remove the now unneeded EchoCancellationImplWrapper. BUG=2894 R=aluebs@webrtc.org Review URL: https://webrtc-codereview.appspot.com/9199004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5620 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_processing/audio_processing.gypi | 1 - .../audio_processing/audio_processing_impl.cc | 20 +++++------ .../audio_processing/audio_processing_impl.h | 17 +++------ .../echo_cancellation_impl.cc | 30 +++++++--------- .../audio_processing/echo_cancellation_impl.h | 19 +++++----- .../echo_cancellation_impl_wrapper.h | 35 ------------------- .../echo_control_mobile_impl.cc | 17 ++++----- .../echo_control_mobile_impl.h | 9 +++-- .../audio_processing/gain_control_impl.cc | 22 ++++++------ .../audio_processing/gain_control_impl.h | 9 +++-- .../audio_processing/high_pass_filter_impl.cc | 15 ++++---- .../audio_processing/high_pass_filter_impl.h | 8 +++-- .../include/audio_processing.h | 8 +++++ .../include/mock_audio_processing.h | 4 +++ .../audio_processing/level_estimator_impl.cc | 11 +++--- .../audio_processing/level_estimator_impl.h | 10 ++++-- .../noise_suppression_impl.cc | 15 ++++---- .../audio_processing/noise_suppression_impl.h | 10 ++++-- .../audio_processing/processing_component.cc | 27 +++++++------- .../audio_processing/processing_component.h | 6 +--- .../audio_processing/voice_detection_impl.cc | 16 ++++----- .../audio_processing/voice_detection_impl.h | 8 +++-- 22 files changed, 147 insertions(+), 170 deletions(-) delete mode 100644 webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h diff --git a/webrtc/modules/audio_processing/audio_processing.gypi b/webrtc/modules/audio_processing/audio_processing.gypi index da6121749..920cbca91 100644 --- a/webrtc/modules/audio_processing/audio_processing.gypi +++ b/webrtc/modules/audio_processing/audio_processing.gypi @@ -56,7 +56,6 @@ 'audio_processing_impl.h', 'echo_cancellation_impl.cc', 'echo_cancellation_impl.h', - 'echo_cancellation_impl_wrapper.h', 'echo_control_mobile_impl.cc', 'echo_control_mobile_impl.h', 'gain_control_impl.cc', diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index 48297fcd0..26b20206a 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -14,7 +14,7 @@ #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h" +#include "webrtc/modules/audio_processing/echo_cancellation_impl.h" #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h" #include "webrtc/modules/audio_processing/gain_control_impl.h" #include "webrtc/modules/audio_processing/high_pass_filter_impl.h" @@ -97,25 +97,25 @@ AudioProcessingImpl::AudioProcessingImpl(const Config& config) num_output_channels_(1), output_will_be_muted_(false), key_pressed_(false) { - echo_cancellation_ = EchoCancellationImplWrapper::Create(this); + echo_cancellation_ = new EchoCancellationImpl(this, crit_); component_list_.push_back(echo_cancellation_); - echo_control_mobile_ = new EchoControlMobileImpl(this); + echo_control_mobile_ = new EchoControlMobileImpl(this, crit_); component_list_.push_back(echo_control_mobile_); - gain_control_ = new GainControlImpl(this); + gain_control_ = new GainControlImpl(this, crit_); component_list_.push_back(gain_control_); - high_pass_filter_ = new HighPassFilterImpl(this); + high_pass_filter_ = new HighPassFilterImpl(this, crit_); component_list_.push_back(high_pass_filter_); - level_estimator_ = new LevelEstimatorImpl(this); + level_estimator_ = new LevelEstimatorImpl(this, crit_); component_list_.push_back(level_estimator_); - noise_suppression_ = new NoiseSuppressionImpl(this); + noise_suppression_ = new NoiseSuppressionImpl(this, crit_); component_list_.push_back(noise_suppression_); - voice_detection_ = new VoiceDetectionImpl(this); + voice_detection_ = new VoiceDetectionImpl(this, crit_); component_list_.push_back(voice_detection_); SetExtraOptions(config); @@ -152,10 +152,6 @@ AudioProcessingImpl::~AudioProcessingImpl() { crit_ = NULL; } -CriticalSectionWrapper* AudioProcessingImpl::crit() const { - return crit_; -} - int AudioProcessingImpl::split_sample_rate_hz() const { return split_sample_rate_hz_; } diff --git a/webrtc/modules/audio_processing/audio_processing_impl.h b/webrtc/modules/audio_processing/audio_processing_impl.h index 09e2192a6..62ea275f1 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.h +++ b/webrtc/modules/audio_processing/audio_processing_impl.h @@ -21,7 +21,7 @@ namespace webrtc { class AudioBuffer; class CriticalSectionWrapper; -class EchoCancellationImplWrapper; +class EchoCancellationImpl; class EchoControlMobileImpl; class FileWrapper; class GainControlImpl; @@ -41,20 +41,9 @@ class Event; class AudioProcessingImpl : public AudioProcessing { public: - enum { - kSampleRate8kHz = 8000, - kSampleRate16kHz = 16000, - kSampleRate32kHz = 32000 - }; - explicit AudioProcessingImpl(const Config& config); virtual ~AudioProcessingImpl(); - CriticalSectionWrapper* crit() const; - - int split_sample_rate_hz() const; - bool was_stream_delay_set() const; - // AudioProcessing methods. virtual int Initialize() OVERRIDE; virtual void SetExtraOptions(const Config& config) OVERRIDE; @@ -64,6 +53,7 @@ class AudioProcessingImpl : public AudioProcessing { } virtual int set_sample_rate_hz(int rate) OVERRIDE; virtual int sample_rate_hz() const OVERRIDE; + virtual int split_sample_rate_hz() const OVERRIDE; virtual int set_num_channels(int input_channels, int output_channels) OVERRIDE; virtual int num_input_channels() const OVERRIDE; @@ -76,6 +66,7 @@ class AudioProcessingImpl : public AudioProcessing { virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE; virtual int set_stream_delay_ms(int delay) OVERRIDE; virtual int stream_delay_ms() const OVERRIDE; + virtual bool was_stream_delay_set() const OVERRIDE; virtual void set_delay_offset_ms(int offset) OVERRIDE; virtual int delay_offset_ms() const OVERRIDE; virtual void set_stream_key_pressed(bool key_pressed) OVERRIDE; @@ -103,7 +94,7 @@ class AudioProcessingImpl : public AudioProcessing { bool synthesis_needed(bool is_data_processed) const; bool analysis_needed(bool is_data_processed) const; - EchoCancellationImplWrapper* echo_cancellation_; + EchoCancellationImpl* echo_cancellation_; EchoControlMobileImpl* echo_control_mobile_; GainControlImpl* gain_control_; HighPassFilterImpl* high_pass_filter_; diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc index 8fa86c3b1..0d6d159b1 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc @@ -18,7 +18,6 @@ extern "C" { } #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" #include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { @@ -56,14 +55,11 @@ AudioProcessing::Error MapError(int err) { } } // namespace -EchoCancellationImplWrapper* EchoCancellationImplWrapper::Create( - const AudioProcessingImpl* audioproc) { - return new EchoCancellationImpl(audioproc); -} - -EchoCancellationImpl::EchoCancellationImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), +EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), apm_(apm), + crit_(crit), drift_compensation_enabled_(false), metrics_enabled_(false), suppression_level_(kModerateSuppression), @@ -168,7 +164,7 @@ int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { } int EchoCancellationImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); // Ensure AEC and AECM are not both enabled. if (enable && apm_->echo_control_mobile()->is_enabled()) { return apm_->kBadParameterError; @@ -182,7 +178,7 @@ bool EchoCancellationImpl::is_enabled() const { } int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (MapSetting(level) == -1) { return apm_->kBadParameterError; } @@ -197,7 +193,7 @@ EchoCancellation::SuppressionLevel EchoCancellationImpl::suppression_level() } int EchoCancellationImpl::enable_drift_compensation(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); drift_compensation_enabled_ = enable; return Configure(); } @@ -207,7 +203,7 @@ bool EchoCancellationImpl::is_drift_compensation_enabled() const { } int EchoCancellationImpl::set_device_sample_rate_hz(int rate) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (rate < 8000 || rate > 96000) { return apm_->kBadParameterError; } @@ -230,7 +226,7 @@ int EchoCancellationImpl::stream_drift_samples() const { } int EchoCancellationImpl::enable_metrics(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); metrics_enabled_ = enable; return Configure(); } @@ -242,7 +238,7 @@ bool EchoCancellationImpl::are_metrics_enabled() const { // TODO(ajm): we currently just use the metrics from the first AEC. Think more // aboue the best way to extend this to multi-channel. int EchoCancellationImpl::GetMetrics(Metrics* metrics) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (metrics == NULL) { return apm_->kNullPointerError; } @@ -289,7 +285,7 @@ bool EchoCancellationImpl::stream_has_echo() const { } int EchoCancellationImpl::enable_delay_logging(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); delay_logging_enabled_ = enable; return Configure(); } @@ -300,7 +296,7 @@ bool EchoCancellationImpl::is_delay_logging_enabled() const { // TODO(bjornv): How should we handle the multi-channel case? int EchoCancellationImpl::GetDelayMetrics(int* median, int* std) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (median == NULL) { return apm_->kNullPointerError; } @@ -322,7 +318,7 @@ int EchoCancellationImpl::GetDelayMetrics(int* median, int* std) { } struct AecCore* EchoCancellationImpl::aec_core() const { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (!is_component_enabled()) { return NULL; } diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.h b/webrtc/modules/audio_processing/echo_cancellation_impl.h index 3ab0ce266..f5572b940 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl.h +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.h @@ -11,21 +11,23 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_H_ -#include "webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h" +#include "webrtc/modules/audio_processing/include/audio_processing.h" +#include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; class AudioBuffer; +class CriticalSectionWrapper; -class EchoCancellationImpl : public EchoCancellationImplWrapper { +class EchoCancellationImpl : public EchoCancellation, + public ProcessingComponent { public: - explicit EchoCancellationImpl(const AudioProcessingImpl* apm); + EchoCancellationImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit); virtual ~EchoCancellationImpl(); - // EchoCancellationImplWrapper implementation. - virtual int ProcessRenderAudio(const AudioBuffer* audio) OVERRIDE; - virtual int ProcessCaptureAudio(AudioBuffer* audio) OVERRIDE; + int ProcessRenderAudio(const AudioBuffer* audio); + int ProcessCaptureAudio(AudioBuffer* audio); // EchoCancellation implementation. virtual bool is_enabled() const OVERRIDE; @@ -62,7 +64,8 @@ class EchoCancellationImpl : public EchoCancellationImplWrapper { virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; bool drift_compensation_enabled_; bool metrics_enabled_; SuppressionLevel suppression_level_; diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h b/webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h deleted file mode 100644 index f1c03f32d..000000000 --- a/webrtc/modules/audio_processing/echo_cancellation_impl_wrapper.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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_ECHO_CANCELLATION_IMPL_WRAPPER_H_ -#define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_WRAPPER_H_ - -#include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/modules/audio_processing/processing_component.h" - -namespace webrtc { - -class AudioProcessingImpl; -class AudioBuffer; - -class EchoCancellationImplWrapper : public virtual EchoCancellation, - public virtual ProcessingComponent { - public: - static EchoCancellationImplWrapper* Create( - const AudioProcessingImpl* audioproc); - virtual ~EchoCancellationImplWrapper() {} - - virtual int ProcessRenderAudio(const AudioBuffer* audio) = 0; - virtual int ProcessCaptureAudio(AudioBuffer* audio) = 0; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_IMPL_WRAPPER_H_ diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc index f78538149..8434b6178 100644 --- a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc +++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc @@ -15,7 +15,6 @@ #include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h" #include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/logging.h" @@ -63,9 +62,11 @@ size_t EchoControlMobile::echo_path_size_bytes() { return WebRtcAecm_echo_path_size_bytes(); } -EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), +EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), apm_(apm), + crit_(crit), routing_mode_(kSpeakerphone), comfort_noise_enabled_(true), external_echo_path_(NULL) {} @@ -155,7 +156,7 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) { } int EchoControlMobileImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); // Ensure AEC and AECM are not both enabled. if (enable && apm_->echo_cancellation()->is_enabled()) { return apm_->kBadParameterError; @@ -169,7 +170,7 @@ bool EchoControlMobileImpl::is_enabled() const { } int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (MapSetting(mode) == -1) { return apm_->kBadParameterError; } @@ -184,7 +185,7 @@ EchoControlMobile::RoutingMode EchoControlMobileImpl::routing_mode() } int EchoControlMobileImpl::enable_comfort_noise(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); comfort_noise_enabled_ = enable; return Configure(); } @@ -195,7 +196,7 @@ bool EchoControlMobileImpl::is_comfort_noise_enabled() const { int EchoControlMobileImpl::SetEchoPath(const void* echo_path, size_t size_bytes) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (echo_path == NULL) { return apm_->kNullPointerError; } @@ -214,7 +215,7 @@ int EchoControlMobileImpl::SetEchoPath(const void* echo_path, int EchoControlMobileImpl::GetEchoPath(void* echo_path, size_t size_bytes) const { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (echo_path == NULL) { return apm_->kNullPointerError; } diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.h b/webrtc/modules/audio_processing/echo_control_mobile_impl.h index 5eefab0a3..f00d59bcf 100644 --- a/webrtc/modules/audio_processing/echo_control_mobile_impl.h +++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.h @@ -15,13 +15,15 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class EchoControlMobileImpl : public EchoControlMobile, public ProcessingComponent { public: - explicit EchoControlMobileImpl(const AudioProcessingImpl* apm); + EchoControlMobileImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit); virtual ~EchoControlMobileImpl(); int ProcessRenderAudio(const AudioBuffer* audio); @@ -51,7 +53,8 @@ class EchoControlMobileImpl : public EchoControlMobile, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; RoutingMode routing_mode_; bool comfort_noise_enabled_; unsigned char* external_echo_path_; diff --git a/webrtc/modules/audio_processing/gain_control_impl.cc b/webrtc/modules/audio_processing/gain_control_impl.cc index a6cd68425..59532210b 100644 --- a/webrtc/modules/audio_processing/gain_control_impl.cc +++ b/webrtc/modules/audio_processing/gain_control_impl.cc @@ -12,12 +12,10 @@ #include +#include "webrtc/modules/audio_processing/audio_buffer.h" #include "webrtc/modules/audio_processing/agc/include/gain_control.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" - namespace webrtc { typedef void Handle; @@ -37,9 +35,11 @@ int16_t MapSetting(GainControl::Mode mode) { } } // namespace -GainControlImpl::GainControlImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), +GainControlImpl::GainControlImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), apm_(apm), + crit_(crit), mode_(kAdaptiveAnalog), minimum_capture_level_(0), maximum_capture_level_(255), @@ -203,7 +203,7 @@ int GainControlImpl::stream_analog_level() { } int GainControlImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); return EnableComponent(enable); } @@ -212,7 +212,7 @@ bool GainControlImpl::is_enabled() const { } int GainControlImpl::set_mode(Mode mode) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (MapSetting(mode) == -1) { return apm_->kBadParameterError; } @@ -227,7 +227,7 @@ GainControl::Mode GainControlImpl::mode() const { int GainControlImpl::set_analog_level_limits(int minimum, int maximum) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (minimum < 0) { return apm_->kBadParameterError; } @@ -259,7 +259,7 @@ bool GainControlImpl::stream_is_saturated() const { } int GainControlImpl::set_target_level_dbfs(int level) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (level > 31 || level < 0) { return apm_->kBadParameterError; } @@ -273,7 +273,7 @@ int GainControlImpl::target_level_dbfs() const { } int GainControlImpl::set_compression_gain_db(int gain) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (gain < 0 || gain > 90) { return apm_->kBadParameterError; } @@ -287,7 +287,7 @@ int GainControlImpl::compression_gain_db() const { } int GainControlImpl::enable_limiter(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); limiter_enabled_ = enable; return Configure(); } diff --git a/webrtc/modules/audio_processing/gain_control_impl.h b/webrtc/modules/audio_processing/gain_control_impl.h index 2de02f6e6..e1669ccc7 100644 --- a/webrtc/modules/audio_processing/gain_control_impl.h +++ b/webrtc/modules/audio_processing/gain_control_impl.h @@ -17,13 +17,15 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class GainControlImpl : public GainControl, public ProcessingComponent { public: - explicit GainControlImpl(const AudioProcessingImpl* apm); + GainControlImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit); virtual ~GainControlImpl(); int ProcessRenderAudio(AudioBuffer* audio); @@ -62,7 +64,8 @@ class GainControlImpl : public GainControl, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; Mode mode_; int minimum_capture_level_; int maximum_capture_level_; diff --git a/webrtc/modules/audio_processing/high_pass_filter_impl.cc b/webrtc/modules/audio_processing/high_pass_filter_impl.cc index da2170373..d4836ef55 100644 --- a/webrtc/modules/audio_processing/high_pass_filter_impl.cc +++ b/webrtc/modules/audio_processing/high_pass_filter_impl.cc @@ -13,11 +13,10 @@ #include #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" +#include "webrtc/modules/audio_processing/audio_buffer.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/typedefs.h" -#include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" namespace webrtc { namespace { @@ -36,7 +35,7 @@ struct FilterState { int InitializeFilter(FilterState* hpf, int sample_rate_hz) { assert(hpf != NULL); - if (sample_rate_hz == AudioProcessingImpl::kSampleRate8kHz) { + if (sample_rate_hz == AudioProcessing::kSampleRate8kHz) { hpf->ba = kFilterCoefficients8kHz; } else { hpf->ba = kFilterCoefficients; @@ -105,9 +104,11 @@ int Filter(FilterState* hpf, int16_t* data, int length) { typedef FilterState Handle; -HighPassFilterImpl::HighPassFilterImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), - apm_(apm) {} +HighPassFilterImpl::HighPassFilterImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), + apm_(apm), + crit_(crit) {} HighPassFilterImpl::~HighPassFilterImpl() {} @@ -135,7 +136,7 @@ int HighPassFilterImpl::ProcessCaptureAudio(AudioBuffer* audio) { } int HighPassFilterImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); return EnableComponent(enable); } diff --git a/webrtc/modules/audio_processing/high_pass_filter_impl.h b/webrtc/modules/audio_processing/high_pass_filter_impl.h index 7e11ea9ce..1796e77ff 100644 --- a/webrtc/modules/audio_processing/high_pass_filter_impl.h +++ b/webrtc/modules/audio_processing/high_pass_filter_impl.h @@ -15,13 +15,14 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class HighPassFilterImpl : public HighPassFilter, public ProcessingComponent { public: - explicit HighPassFilterImpl(const AudioProcessingImpl* apm); + HighPassFilterImpl(const AudioProcessing* apm, CriticalSectionWrapper* crit); virtual ~HighPassFilterImpl(); int ProcessCaptureAudio(AudioBuffer* audio); @@ -41,7 +42,8 @@ class HighPassFilterImpl : public HighPassFilter, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/include/audio_processing.h b/webrtc/modules/audio_processing/include/audio_processing.h index c34baacb8..f41c88663 100644 --- a/webrtc/modules/audio_processing/include/audio_processing.h +++ b/webrtc/modules/audio_processing/include/audio_processing.h @@ -168,6 +168,7 @@ class AudioProcessing { // streams. 8000, 16000 or 32000 Hz are permitted. virtual int set_sample_rate_hz(int rate) = 0; virtual int sample_rate_hz() const = 0; + virtual int split_sample_rate_hz() const = 0; // DEPRECATED: It is now possible to modify the number of channels directly in // a call to |ProcessStream|. @@ -236,6 +237,7 @@ class AudioProcessing { // ProcessStream(). virtual int set_stream_delay_ms(int delay) = 0; virtual int stream_delay_ms() const = 0; + virtual bool was_stream_delay_set() const = 0; // Call to signal that a key press occurred (true) or did not occur (false) // with this chunk of audio. @@ -304,6 +306,12 @@ class AudioProcessing { // will continue, but the parameter may have been truncated. kBadStreamParameterWarning = -13 }; + + enum { + kSampleRate8kHz = 8000, + kSampleRate16kHz = 16000, + kSampleRate32kHz = 32000 + }; }; // The acoustic echo cancellation (AEC) component provides better performance diff --git a/webrtc/modules/audio_processing/include/mock_audio_processing.h b/webrtc/modules/audio_processing/include/mock_audio_processing.h index 762f21238..5feafc032 100644 --- a/webrtc/modules/audio_processing/include/mock_audio_processing.h +++ b/webrtc/modules/audio_processing/include/mock_audio_processing.h @@ -191,6 +191,8 @@ class MockAudioProcessing : public AudioProcessing { int(int rate)); MOCK_CONST_METHOD0(sample_rate_hz, int()); + MOCK_CONST_METHOD0(split_sample_rate_hz, + int()); MOCK_METHOD2(set_num_channels, int(int input_channels, int output_channels)); MOCK_CONST_METHOD0(num_input_channels, @@ -213,6 +215,8 @@ class MockAudioProcessing : public AudioProcessing { int(int delay)); MOCK_CONST_METHOD0(stream_delay_ms, int()); + MOCK_CONST_METHOD0(was_stream_delay_set, + bool()); MOCK_METHOD1(set_stream_key_pressed, void(bool key_pressed)); MOCK_CONST_METHOD0(stream_key_pressed, diff --git a/webrtc/modules/audio_processing/level_estimator_impl.cc b/webrtc/modules/audio_processing/level_estimator_impl.cc index 29dbdfc78..a512ef157 100644 --- a/webrtc/modules/audio_processing/level_estimator_impl.cc +++ b/webrtc/modules/audio_processing/level_estimator_impl.cc @@ -15,7 +15,6 @@ #include #include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { @@ -84,9 +83,11 @@ class Level { }; } // namespace -LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), - apm_(apm) {} +LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), + apm_(apm), + crit_(crit) {} LevelEstimatorImpl::~LevelEstimatorImpl() {} @@ -113,7 +114,7 @@ int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { } int LevelEstimatorImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); return EnableComponent(enable); } diff --git a/webrtc/modules/audio_processing/level_estimator_impl.h b/webrtc/modules/audio_processing/level_estimator_impl.h index 20dc18dc4..2490d7930 100644 --- a/webrtc/modules/audio_processing/level_estimator_impl.h +++ b/webrtc/modules/audio_processing/level_estimator_impl.h @@ -15,13 +15,15 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class LevelEstimatorImpl : public LevelEstimator, public ProcessingComponent { public: - explicit LevelEstimatorImpl(const AudioProcessingImpl* apm); + LevelEstimatorImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit); virtual ~LevelEstimatorImpl(); int ProcessStream(AudioBuffer* audio); @@ -42,8 +44,10 @@ class LevelEstimatorImpl : public LevelEstimator, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; }; + } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ diff --git a/webrtc/modules/audio_processing/noise_suppression_impl.cc b/webrtc/modules/audio_processing/noise_suppression_impl.cc index 41c11b1cd..9ecbf8d37 100644 --- a/webrtc/modules/audio_processing/noise_suppression_impl.cc +++ b/webrtc/modules/audio_processing/noise_suppression_impl.cc @@ -12,15 +12,14 @@ #include -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" +#include "webrtc/modules/audio_processing/audio_buffer.h" #if defined(WEBRTC_NS_FLOAT) #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h" #elif defined(WEBRTC_NS_FIXED) #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h" #endif +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" namespace webrtc { @@ -47,9 +46,11 @@ int MapSetting(NoiseSuppression::Level level) { } } // namespace -NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), +NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), apm_(apm), + crit_(crit), level_(kModerate) {} NoiseSuppressionImpl::~NoiseSuppressionImpl() {} @@ -88,7 +89,7 @@ int NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { } int NoiseSuppressionImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); return EnableComponent(enable); } @@ -97,7 +98,7 @@ bool NoiseSuppressionImpl::is_enabled() const { } int NoiseSuppressionImpl::set_level(Level level) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (MapSetting(level) == -1) { return apm_->kBadParameterError; } diff --git a/webrtc/modules/audio_processing/noise_suppression_impl.h b/webrtc/modules/audio_processing/noise_suppression_impl.h index f6dd8cbd7..46b7be2fe 100644 --- a/webrtc/modules/audio_processing/noise_suppression_impl.h +++ b/webrtc/modules/audio_processing/noise_suppression_impl.h @@ -15,13 +15,15 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class NoiseSuppressionImpl : public NoiseSuppression, public ProcessingComponent { public: - explicit NoiseSuppressionImpl(const AudioProcessingImpl* apm); + NoiseSuppressionImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit); virtual ~NoiseSuppressionImpl(); int ProcessCaptureAudio(AudioBuffer* audio); @@ -44,9 +46,11 @@ class NoiseSuppressionImpl : public NoiseSuppression, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; Level level_; }; + } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_PROCESSING_NOISE_SUPPRESSION_IMPL_H_ diff --git a/webrtc/modules/audio_processing/processing_component.cc b/webrtc/modules/audio_processing/processing_component.cc index 23bf22570..9e16d7c4e 100644 --- a/webrtc/modules/audio_processing/processing_component.cc +++ b/webrtc/modules/audio_processing/processing_component.cc @@ -12,15 +12,12 @@ #include -#include "webrtc/modules/audio_processing/audio_processing_impl.h" +#include "webrtc/modules/audio_processing/include/audio_processing.h" namespace webrtc { -ProcessingComponent::ProcessingComponent() {} - -ProcessingComponent::ProcessingComponent(const AudioProcessingImpl* apm) - : apm_(apm), - initialized_(false), +ProcessingComponent::ProcessingComponent() + : initialized_(false), enabled_(false), num_handles_(0) {} @@ -35,7 +32,7 @@ int ProcessingComponent::Destroy() { } initialized_ = false; - return apm_->kNoError; + return AudioProcessing::kNoError; } int ProcessingComponent::EnableComponent(bool enable) { @@ -43,7 +40,7 @@ int ProcessingComponent::EnableComponent(bool enable) { enabled_ = enable; // Must be set before Initialize() is called. int err = Initialize(); - if (err != apm_->kNoError) { + if (err != AudioProcessing::kNoError) { enabled_ = false; return err; } @@ -51,7 +48,7 @@ int ProcessingComponent::EnableComponent(bool enable) { enabled_ = enable; } - return apm_->kNoError; + return AudioProcessing::kNoError; } bool ProcessingComponent::is_component_enabled() const { @@ -69,7 +66,7 @@ int ProcessingComponent::num_handles() const { int ProcessingComponent::Initialize() { if (!enabled_) { - return apm_->kNoError; + return AudioProcessing::kNoError; } num_handles_ = num_handles_required(); @@ -82,12 +79,12 @@ int ProcessingComponent::Initialize() { if (handles_[i] == NULL) { handles_[i] = CreateHandle(); if (handles_[i] == NULL) { - return apm_->kCreationFailedError; + return AudioProcessing::kCreationFailedError; } } int err = InitializeHandle(handles_[i]); - if (err != apm_->kNoError) { + if (err != AudioProcessing::kNoError) { return GetHandleError(handles_[i]); } } @@ -98,17 +95,17 @@ int ProcessingComponent::Initialize() { int ProcessingComponent::Configure() { if (!initialized_) { - return apm_->kNoError; + return AudioProcessing::kNoError; } assert(static_cast(handles_.size()) >= num_handles_); for (int i = 0; i < num_handles_; i++) { int err = ConfigureHandle(handles_[i]); - if (err != apm_->kNoError) { + if (err != AudioProcessing::kNoError) { return GetHandleError(handles_[i]); } } - return apm_->kNoError; + return AudioProcessing::kNoError; } } // namespace webrtc diff --git a/webrtc/modules/audio_processing/processing_component.h b/webrtc/modules/audio_processing/processing_component.h index c090d2224..27400998e 100644 --- a/webrtc/modules/audio_processing/processing_component.h +++ b/webrtc/modules/audio_processing/processing_component.h @@ -13,16 +13,13 @@ #include -#include "webrtc/modules/audio_processing/include/audio_processing.h" +#include "webrtc/common.h" namespace webrtc { -class AudioProcessingImpl; - class ProcessingComponent { public: ProcessingComponent(); - explicit ProcessingComponent(const AudioProcessingImpl* apm); virtual ~ProcessingComponent(); virtual int Initialize(); @@ -45,7 +42,6 @@ class ProcessingComponent { virtual int num_handles_required() const = 0; virtual int GetHandleError(void* handle) const = 0; - const AudioProcessingImpl* apm_; std::vector handles_; bool initialized_; bool enabled_; diff --git a/webrtc/modules/audio_processing/voice_detection_impl.cc b/webrtc/modules/audio_processing/voice_detection_impl.cc index d41547c80..1b1dd8b80 100644 --- a/webrtc/modules/audio_processing/voice_detection_impl.cc +++ b/webrtc/modules/audio_processing/voice_detection_impl.cc @@ -13,10 +13,8 @@ #include #include "webrtc/common_audio/vad/include/webrtc_vad.h" -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" - #include "webrtc/modules/audio_processing/audio_buffer.h" -#include "webrtc/modules/audio_processing/audio_processing_impl.h" +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { @@ -39,9 +37,11 @@ int MapSetting(VoiceDetection::Likelihood likelihood) { } } // namespace -VoiceDetectionImpl::VoiceDetectionImpl(const AudioProcessingImpl* apm) - : ProcessingComponent(apm), +VoiceDetectionImpl::VoiceDetectionImpl(const AudioProcessing* apm, + CriticalSectionWrapper* crit) + : ProcessingComponent(), apm_(apm), + crit_(crit), stream_has_voice_(false), using_external_vad_(false), likelihood_(kLowLikelihood), @@ -87,7 +87,7 @@ int VoiceDetectionImpl::ProcessCaptureAudio(AudioBuffer* audio) { } int VoiceDetectionImpl::Enable(bool enable) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); return EnableComponent(enable); } @@ -108,7 +108,7 @@ bool VoiceDetectionImpl::stream_has_voice() const { } int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); if (MapSetting(likelihood) == -1) { return apm_->kBadParameterError; } @@ -122,7 +122,7 @@ VoiceDetection::Likelihood VoiceDetectionImpl::likelihood() const { } int VoiceDetectionImpl::set_frame_size_ms(int size) { - CriticalSectionScoped crit_scoped(apm_->crit()); + CriticalSectionScoped crit_scoped(crit_); assert(size == 10); // TODO(ajm): remove when supported. if (size != 10 && size != 20 && diff --git a/webrtc/modules/audio_processing/voice_detection_impl.h b/webrtc/modules/audio_processing/voice_detection_impl.h index f8f50e849..5d06517a4 100644 --- a/webrtc/modules/audio_processing/voice_detection_impl.h +++ b/webrtc/modules/audio_processing/voice_detection_impl.h @@ -15,13 +15,14 @@ #include "webrtc/modules/audio_processing/processing_component.h" namespace webrtc { -class AudioProcessingImpl; + class AudioBuffer; +class CriticalSectionWrapper; class VoiceDetectionImpl : public VoiceDetection, public ProcessingComponent { public: - explicit VoiceDetectionImpl(const AudioProcessingImpl* apm); + VoiceDetectionImpl(const AudioProcessing* apm, CriticalSectionWrapper* crit); virtual ~VoiceDetectionImpl(); int ProcessCaptureAudio(AudioBuffer* audio); @@ -50,7 +51,8 @@ class VoiceDetectionImpl : public VoiceDetection, virtual int num_handles_required() const OVERRIDE; virtual int GetHandleError(void* handle) const OVERRIDE; - const AudioProcessingImpl* apm_; + const AudioProcessing* apm_; + CriticalSectionWrapper* crit_; bool stream_has_voice_; bool using_external_vad_; Likelihood likelihood_;