Index: webrtc/modules/audio_processing/echo_cancellation_impl.cc |
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc |
index 07f96fa170564a189256b3e4da77826f7a81ba3b..5e05055369a53e1f721e9fa65093d7b2c810186d 100644 |
--- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc |
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc |
@@ -16,9 +16,9 @@ |
extern "C" { |
#include "webrtc/modules/audio_processing/aec/aec_core.h" |
} |
+#include "webrtc/base/criticalsection.h" |
#include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" |
#include "webrtc/modules/audio_processing/audio_buffer.h" |
-#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
namespace webrtc { |
@@ -59,12 +59,14 @@ const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame1; |
const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame2; |
EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
- CriticalSectionWrapper* crit, |
+ rtc::CriticalSection* crit_render, |
+ rtc::CriticalSection* crit_capture, |
rtc::ThreadChecker* render_thread, |
rtc::ThreadChecker* capture_thread) |
: ProcessingComponent(), |
apm_(apm), |
- crit_(crit), |
+ crit_render_(crit_render), |
+ crit_capture_(crit_capture), |
render_thread_(render_thread), |
capture_thread_(capture_thread), |
drift_compensation_enabled_(false), |
@@ -221,7 +223,9 @@ int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
} |
int EchoCancellationImpl::Enable(bool enable) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ // Run in a single-threaded manner. |
+ rtc::CritScope cs_render(crit_render_); |
+ rtc::CritScope cs_capture(crit_capture_); |
// Ensure AEC and AECM are not both enabled. |
if (enable && apm_->echo_control_mobile()->is_enabled()) { |
return apm_->kBadParameterError; |
@@ -231,11 +235,12 @@ int EchoCancellationImpl::Enable(bool enable) { |
} |
bool EchoCancellationImpl::is_enabled() const { |
+ rtc::CritScope cs(crit_capture_); |
return is_component_enabled(); |
} |
int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ rtc::CritScope cs(crit_capture_); |
if (MapSetting(level) == -1) { |
return apm_->kBadParameterError; |
} |
@@ -246,42 +251,47 @@ int EchoCancellationImpl::set_suppression_level(SuppressionLevel level) { |
EchoCancellation::SuppressionLevel EchoCancellationImpl::suppression_level() |
const { |
+ rtc::CritScope cs(crit_capture_); |
return suppression_level_; |
} |
int EchoCancellationImpl::enable_drift_compensation(bool enable) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ rtc::CritScope cs(crit_capture_); |
drift_compensation_enabled_ = enable; |
return Configure(); |
} |
bool EchoCancellationImpl::is_drift_compensation_enabled() const { |
+ rtc::CritScope cs(crit_capture_); |
return drift_compensation_enabled_; |
} |
void EchoCancellationImpl::set_stream_drift_samples(int drift) { |
+ rtc::CritScope cs(crit_capture_); |
was_stream_drift_set_ = true; |
stream_drift_samples_ = drift; |
} |
int EchoCancellationImpl::stream_drift_samples() const { |
+ rtc::CritScope cs(crit_capture_); |
return stream_drift_samples_; |
} |
int EchoCancellationImpl::enable_metrics(bool enable) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ rtc::CritScope cs(crit_capture_); |
metrics_enabled_ = enable; |
return Configure(); |
} |
bool EchoCancellationImpl::are_metrics_enabled() const { |
+ rtc::CritScope cs(crit_capture_); |
return metrics_enabled_; |
} |
// 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(crit_); |
+ rtc::CritScope cs(crit_capture_); |
if (metrics == NULL) { |
return apm_->kNullPointerError; |
} |
@@ -328,12 +338,13 @@ bool EchoCancellationImpl::stream_has_echo() const { |
} |
int EchoCancellationImpl::enable_delay_logging(bool enable) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ rtc::CritScope cs(crit_capture_); |
delay_logging_enabled_ = enable; |
return Configure(); |
} |
bool EchoCancellationImpl::is_delay_logging_enabled() const { |
+ rtc::CritScope cs(crit_capture_); |
return delay_logging_enabled_; |
} |
@@ -347,13 +358,14 @@ bool EchoCancellationImpl::is_extended_filter_enabled() const { |
// TODO(bjornv): How should we handle the multi-channel case? |
int EchoCancellationImpl::GetDelayMetrics(int* median, int* std) { |
+ rtc::CritScope cs(crit_capture_); |
float fraction_poor_delays = 0; |
return GetDelayMetrics(median, std, &fraction_poor_delays); |
} |
int EchoCancellationImpl::GetDelayMetrics(int* median, int* std, |
float* fraction_poor_delays) { |
- CriticalSectionScoped crit_scoped(crit_); |
+ rtc::CritScope cs(crit_capture_); |
if (median == NULL) { |
return apm_->kNullPointerError; |
} |
@@ -376,7 +388,6 @@ int EchoCancellationImpl::GetDelayMetrics(int* median, int* std, |
} |
struct AecCore* EchoCancellationImpl::aec_core() const { |
- CriticalSectionScoped crit_scoped(crit_); |
if (!is_component_enabled()) { |
return NULL; |
} |