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

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: Major general updates, completing the locking scheme, and increasing readability 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 9210499ad25215f2303e34a617d70a94b51be150..ac7139c3e1798f3e4d070de299a73056a58ddf5f 100644
--- a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
+++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc
@@ -13,9 +13,9 @@
#include <assert.h>
#include <string.h>
+#include "webrtc/base/criticalsection.h"
#include "webrtc/modules/audio_processing/aecm/include/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 {
@@ -67,11 +67,13 @@ size_t EchoControlMobile::echo_path_size_bytes() {
EchoControlMobileImpl::EchoControlMobileImpl(
const AudioProcessing* apm,
- CriticalSectionWrapper* crit,
+ rtc::CriticalSection* crit_render,
+ rtc::CriticalSection* crit_capture,
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),
@@ -121,9 +123,18 @@ int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
}
}
- // Check of success is temporarily disabled as it breaks a unit test.
- // TODO(peah): Will be fixed in the next CL.
- (void)render_signal_queue_->Insert(&render_queue_buffer_);
+ // Insert the samples into the queue.
+ bool success = render_signal_queue_->Insert(&render_queue_buffer_);
+ if (!success) {
hlundin-webrtc 2015/11/05 16:11:22 if (!render_signal_queue_->Insert(&render_queue_bu
peah-webrtc 2015/11/06 09:54:32 Done.
+ // 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);
+ }
return apm_->kNoError;
}
@@ -201,7 +212,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;
@@ -211,11 +224,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;
}
@@ -226,22 +240,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;
}
@@ -260,7 +277,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;
}
@@ -282,6 +299,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;
}
@@ -302,6 +320,7 @@ int EchoControlMobileImpl::Initialize() {
}
void EchoControlMobileImpl::AllocateRenderQueue() {
+ // Only called from within APM, hence no locking is needed.
const size_t max_frame_size = std::max(kAllowedValuesOfSamplesPerFrame1,
kAllowedValuesOfSamplesPerFrame2);
const size_t new_render_queue_element_max_size =
@@ -328,14 +347,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) {
@@ -353,6 +375,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_);
@@ -361,11 +384,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