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
This commit is contained in:
andrew@webrtc.org 2014-02-27 22:23:17 +00:00
parent 806768a6ca
commit 56e4a05053
22 changed files with 147 additions and 170 deletions

View File

@ -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',

View File

@ -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_;
}

View File

@ -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_;

View File

@ -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;
}

View File

@ -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_;

View File

@ -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_

View File

@ -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;
}

View File

@ -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_;

View File

@ -12,12 +12,10 @@
#include <assert.h>
#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();
}

View File

@ -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_;

View File

@ -13,11 +13,10 @@
#include <assert.h>
#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);
}

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -15,7 +15,6 @@
#include <string.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 {
@ -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);
}

View File

@ -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_

View File

@ -12,15 +12,14 @@
#include <assert.h>
#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;
}

View File

@ -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_

View File

@ -12,15 +12,12 @@
#include <assert.h>
#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<int>(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

View File

@ -13,16 +13,13 @@
#include <vector>
#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<void*> handles_;
bool initialized_;
bool enabled_;

View File

@ -13,10 +13,8 @@
#include <assert.h>
#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 &&

View File

@ -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_;