Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: webrtc/modules/audio_processing/echo_control_mobile_impl.cc

Issue 1424663003: Lock scheme #8: Introduced the new locking scheme (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@add_threadcheckers_CL
Patch Set: Changes in response to reviewer comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/echo_control_mobile_impl.cc
diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
index a653519fe22a70829c562ed53538857f9b1269cb..ca5f0b3a2a28106eba6f49d4e2f13f076836e2c1 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/echo_control_mobile.h"
#include "webrtc/modules/audio_processing/audio_buffer.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/logging.h"
namespace webrtc {
@@ -70,11 +69,13 @@ size_t EchoControlMobile::echo_path_size_bytes() {
EchoControlMobileImpl::EchoControlMobileImpl(
const AudioProcessing* apm,
- CriticalSectionWrapper* crit,
+ rtc::CriticalSection* crit_render,
+ rtc::CriticalSection* crit_capture,
const rtc::ThreadChecker* render_thread_checker)
: ProcessingComponent(),
apm_(apm),
- crit_(crit),
+ crit_render_(crit_render),
+ crit_capture_(crit_capture),
render_thread_checker_(render_thread_checker),
routing_mode_(kSpeakerphone),
comfort_noise_enabled_(true),
@@ -124,7 +125,11 @@ int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
// Insert the samples into the queue.
if (!render_signal_queue_->Insert(&render_queue_buffer_)) {
- ReadQueuedRenderData();
+ // The data queue is full and needs to be emptied.
+ {
+ rtc::CritScope cs_capture(crit_capture_);
+ ReadQueuedRenderData();
+ }
// Retry the insert (should always work).
RTC_DCHECK_EQ(render_signal_queue_->Insert(&render_queue_buffer_), true);
@@ -205,7 +210,9 @@ int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
}
int EchoControlMobileImpl::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_cancellation()->is_enabled()) {
return apm_->kBadParameterError;
@@ -215,11 +222,12 @@ int EchoControlMobileImpl::Enable(bool enable) {
}
bool EchoControlMobileImpl::is_enabled() const {
+ rtc::CritScope cs(crit_capture_);
return is_component_enabled();
}
int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) {
- CriticalSectionScoped crit_scoped(crit_);
+ rtc::CritScope cs(crit_capture_);
if (MapSetting(mode) == -1) {
return apm_->kBadParameterError;
}
@@ -230,22 +238,25 @@ int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) {
EchoControlMobile::RoutingMode EchoControlMobileImpl::routing_mode()
const {
+ rtc::CritScope cs(crit_capture_);
return routing_mode_;
}
int EchoControlMobileImpl::enable_comfort_noise(bool enable) {
- CriticalSectionScoped crit_scoped(crit_);
+ rtc::CritScope cs(crit_capture_);
comfort_noise_enabled_ = enable;
return Configure();
}
bool EchoControlMobileImpl::is_comfort_noise_enabled() const {
+ rtc::CritScope cs(crit_capture_);
return comfort_noise_enabled_;
}
int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
size_t size_bytes) {
- CriticalSectionScoped crit_scoped(crit_);
+ rtc::CritScope cs_render(crit_render_);
+ rtc::CritScope cs_capture(crit_capture_);
if (echo_path == NULL) {
return apm_->kNullPointerError;
}
@@ -264,7 +275,7 @@ int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
int EchoControlMobileImpl::GetEchoPath(void* echo_path,
size_t size_bytes) const {
- CriticalSectionScoped crit_scoped(crit_);
+ rtc::CritScope cs(crit_capture_);
if (echo_path == NULL) {
return apm_->kNullPointerError;
}
@@ -286,6 +297,7 @@ int EchoControlMobileImpl::GetEchoPath(void* echo_path,
}
int EchoControlMobileImpl::Initialize() {
+ // Only called from within APM, hence no locking is needed.
if (!is_component_enabled()) {
return apm_->kNoError;
}
@@ -330,14 +342,17 @@ void EchoControlMobileImpl::AllocateRenderQueue() {
}
void* EchoControlMobileImpl::CreateHandle() const {
+ // Only called from within APM, hence no locking is needed.
return WebRtcAecm_Create();
}
void EchoControlMobileImpl::DestroyHandle(void* handle) const {
+ // Only called from within APM, hence no locking is needed.
WebRtcAecm_Free(static_cast<Handle*>(handle));
}
int EchoControlMobileImpl::InitializeHandle(void* handle) const {
+ // Only called from within APM, hence no locking is needed.
assert(handle != NULL);
Handle* my_handle = static_cast<Handle*>(handle);
if (WebRtcAecm_Init(my_handle, apm_->proc_sample_rate_hz()) != 0) {
@@ -355,6 +370,7 @@ int EchoControlMobileImpl::InitializeHandle(void* handle) const {
}
int EchoControlMobileImpl::ConfigureHandle(void* handle) const {
+ // Only called from within APM, hence no locking is needed.
AecmConfig config;
config.cngMode = comfort_noise_enabled_;
config.echoMode = MapSetting(routing_mode_);
@@ -363,11 +379,13 @@ int EchoControlMobileImpl::ConfigureHandle(void* handle) const {
}
int EchoControlMobileImpl::num_handles_required() const {
+ // Only called from within APM, hence no locking is needed.
return apm_->num_output_channels() *
apm_->num_reverse_channels();
}
int EchoControlMobileImpl::GetHandleError(void* handle) const {
+ // Only called from within APM, hence no locking is needed.
assert(handle != NULL);
return AudioProcessing::kUnspecifiedError;
}

Powered by Google App Engine
This is Rietveld 408576698