Chromium Code Reviews| Index: webrtc/modules/audio_processing/gain_control_impl.cc |
| diff --git a/webrtc/modules/audio_processing/gain_control_impl.cc b/webrtc/modules/audio_processing/gain_control_impl.cc |
| index e0883ebfcaf9728a361cd8e6197c551d8acb2294..a4a17846dc1d69c8e9639de7fa147a41339c7f6a 100644 |
| --- a/webrtc/modules/audio_processing/gain_control_impl.cc |
| +++ b/webrtc/modules/audio_processing/gain_control_impl.cc |
| @@ -12,9 +12,9 @@ |
| #include <assert.h> |
| +#include "webrtc/base/criticalsection.h" |
| #include "webrtc/modules/audio_processing/audio_buffer.h" |
| #include "webrtc/modules/audio_processing/agc/legacy/gain_control.h" |
| -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| namespace webrtc { |
| @@ -39,12 +39,14 @@ const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame1; |
| const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame2; |
| GainControlImpl::GainControlImpl(const AudioProcessing* apm, |
| - CriticalSectionWrapper* crit, |
| + rtc::CriticalSection* crit_render, |
| + rtc::CriticalSection* crit_capture, |
| rtc::ThreadChecker* render_thread_checker, |
| rtc::ThreadChecker* capture_thread_checker) |
| : ProcessingComponent(), |
| apm_(apm), |
| - crit_(crit), |
| + crit_render_(crit_render), |
| + crit_capture_(crit_capture), |
| render_thread_checker_(render_thread_checker), |
| capture_thread_checker_(capture_thread_checker), |
| mode_(kAdaptiveAnalog), |
| @@ -85,9 +87,18 @@ int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
| (audio->mixed_low_pass_data() + audio->num_frames_per_band())); |
| } |
| - // 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_); |
|
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.
|
| + if (!success) { |
| + // 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; |
| } |
| @@ -225,7 +236,7 @@ int GainControlImpl::set_stream_analog_level(int level) { |
| // places if not needed. |
| ReadQueuedRenderData(); |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs(crit_capture_); |
| was_analog_level_set_ = true; |
| if (level < minimum_capture_level_ || level > maximum_capture_level_) { |
| return apm_->kBadParameterError; |
| @@ -236,6 +247,7 @@ int GainControlImpl::set_stream_analog_level(int level) { |
| } |
| int GainControlImpl::stream_analog_level() { |
| + rtc::CritScope cs(crit_capture_); |
| RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); |
| // TODO(ajm): enable this assertion? |
| //assert(mode_ == kAdaptiveAnalog); |
| @@ -244,16 +256,19 @@ int GainControlImpl::stream_analog_level() { |
| } |
| int GainControlImpl::Enable(bool enable) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs_render(crit_render_); |
| + rtc::CritScope cs(crit_capture_); |
| return EnableComponent(enable); |
| } |
| bool GainControlImpl::is_enabled() const { |
| + rtc::CritScope cs(crit_capture_); |
| return is_component_enabled(); |
| } |
| int GainControlImpl::set_mode(Mode mode) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs_render(crit_render_); |
| + rtc::CritScope cs_capture(crit_capture_); |
| if (MapSetting(mode) == -1) { |
| return apm_->kBadParameterError; |
| } |
| @@ -263,12 +278,13 @@ int GainControlImpl::set_mode(Mode mode) { |
| } |
| GainControl::Mode GainControlImpl::mode() const { |
| + rtc::CritScope cs(crit_capture_); |
| return mode_; |
| } |
| int GainControlImpl::set_analog_level_limits(int minimum, |
| int maximum) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs(crit_capture_); |
| if (minimum < 0) { |
| return apm_->kBadParameterError; |
| } |
| @@ -288,19 +304,22 @@ int GainControlImpl::set_analog_level_limits(int minimum, |
| } |
| int GainControlImpl::analog_level_minimum() const { |
| + rtc::CritScope cs(crit_capture_); |
| return minimum_capture_level_; |
| } |
| int GainControlImpl::analog_level_maximum() const { |
| + rtc::CritScope cs(crit_capture_); |
| return maximum_capture_level_; |
| } |
| bool GainControlImpl::stream_is_saturated() const { |
| + rtc::CritScope cs(crit_capture_); |
| return stream_is_saturated_; |
| } |
| int GainControlImpl::set_target_level_dbfs(int level) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs(crit_capture_); |
| if (level > 31 || level < 0) { |
| return apm_->kBadParameterError; |
| } |
| @@ -310,11 +329,12 @@ int GainControlImpl::set_target_level_dbfs(int level) { |
| } |
| int GainControlImpl::target_level_dbfs() const { |
| + rtc::CritScope cs(crit_capture_); |
| return target_level_dbfs_; |
| } |
| int GainControlImpl::set_compression_gain_db(int gain) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs(crit_capture_); |
| if (gain < 0 || gain > 90) { |
| return apm_->kBadParameterError; |
| } |
| @@ -324,16 +344,18 @@ int GainControlImpl::set_compression_gain_db(int gain) { |
| } |
| int GainControlImpl::compression_gain_db() const { |
| + rtc::CritScope cs(crit_capture_); |
| return compression_gain_db_; |
| } |
| int GainControlImpl::enable_limiter(bool enable) { |
| - CriticalSectionScoped crit_scoped(crit_); |
| + rtc::CritScope cs(crit_capture_); |
| limiter_enabled_ = enable; |
| return Configure(); |
| } |
| bool GainControlImpl::is_limiter_enabled() const { |
| + rtc::CritScope cs(crit_capture_); |
| return limiter_enabled_; |
| } |
| @@ -350,6 +372,7 @@ int GainControlImpl::Initialize() { |
| } |
| void GainControlImpl::AllocateRenderQueue() { |
| + // Only called from within APM, hence no locking is needed. |
| const size_t max_frame_size = std::max(kAllowedValuesOfSamplesPerFrame1, |
| kAllowedValuesOfSamplesPerFrame2); |
| @@ -373,14 +396,17 @@ void GainControlImpl::AllocateRenderQueue() { |
| } |
| void* GainControlImpl::CreateHandle() const { |
| + // Only called from within APM, hence no locking is needed. |
| return WebRtcAgc_Create(); |
| } |
| void GainControlImpl::DestroyHandle(void* handle) const { |
| + // Only called from within APM, hence no locking is needed. |
| WebRtcAgc_Free(static_cast<Handle*>(handle)); |
| } |
| int GainControlImpl::InitializeHandle(void* handle) const { |
| + // Only called from within APM, hence no locking is needed. |
| return WebRtcAgc_Init(static_cast<Handle*>(handle), |
| minimum_capture_level_, |
| maximum_capture_level_, |
| @@ -389,6 +415,7 @@ int GainControlImpl::InitializeHandle(void* handle) const { |
| } |
| int GainControlImpl::ConfigureHandle(void* handle) const { |
| + // Only called from within APM, hence no locking is needed. |
| WebRtcAgcConfig config; |
| // TODO(ajm): Flip the sign here (since AGC expects a positive value) if we |
| // change the interface. |
| @@ -403,10 +430,12 @@ int GainControlImpl::ConfigureHandle(void* handle) const { |
| } |
| int GainControlImpl::num_handles_required() const { |
| + // Only called from within APM, hence no locking is needed. |
| return apm_->num_output_channels(); |
| } |
| int GainControlImpl::GetHandleError(void* handle) const { |
| + // Only called from within APM, hence no locking is needed. |
| // The AGC has no get_error() function. |
| // (Despite listing errors in its interface...) |
| assert(handle != NULL); |