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 8a3612dce5a7b7ea9c2b5a6c128329a3168b2da9..dcc061b592230b1125b8847d652fa8d3e72a10ef 100644 |
| --- a/webrtc/modules/audio_processing/gain_control_impl.cc |
| +++ b/webrtc/modules/audio_processing/gain_control_impl.cc |
| @@ -37,18 +37,27 @@ int16_t MapSetting(GainControl::Mode mode) { |
| GainControlImpl::GainControlImpl(const AudioProcessing* apm, |
| CriticalSectionWrapper* crit) |
| - : ProcessingComponent(), |
| - apm_(apm), |
| - crit_(crit), |
| - mode_(kAdaptiveAnalog), |
| - minimum_capture_level_(0), |
| - maximum_capture_level_(255), |
| - limiter_enabled_(true), |
| - target_level_dbfs_(3), |
| - compression_gain_db_(9), |
| - analog_capture_level_(0), |
| - was_analog_level_set_(false), |
| - stream_is_saturated_(false) {} |
| + : ProcessingComponent(), |
| + apm_(apm), |
| + crit_(crit), |
| + mode_(kAdaptiveAnalog), |
| + minimum_capture_level_(0), |
| + maximum_capture_level_(255), |
| + limiter_enabled_(true), |
| + target_level_dbfs_(3), |
| + compression_gain_db_(9), |
| + analog_capture_level_(0), |
| + was_analog_level_set_(false), |
| + stream_is_saturated_(false), |
| + render_queue_buffer_(kNumSamplesPerFrameToBuffer), |
| + capture_queue_buffer_(kNumSamplesPerFrameToBuffer) { |
| + std::vector<int16_t> template_queue_element(kNumSamplesPerFrameToBuffer); |
| + |
| + render_signal_queue_.reset( |
| + new SwapQueue<std::vector<int16_t>, &RenderQueueItemVerifier>( |
| + (kMaxNumFramesToBuffer * kMaxNumChannelsPerFrameToBuffer), |
| + template_queue_element)); |
| +} |
| GainControlImpl::~GainControlImpl() {} |
| @@ -61,19 +70,44 @@ int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
| for (int i = 0; i < num_handles(); i++) { |
| Handle* my_handle = static_cast<Handle*>(handle(i)); |
| - int err = WebRtcAgc_AddFarend( |
| - my_handle, |
| - audio->mixed_low_pass_data(), |
| - audio->num_frames_per_band()); |
| + int err = |
| + WebRtcAgc_GetAddFarendError(my_handle, audio->num_frames_per_band()); |
| - if (err != apm_->kNoError) { |
| + if (err != apm_->kNoError) |
| return GetHandleError(my_handle); |
| - } |
| + |
| + // Buffer the samples in the render queue. |
| + // TODO(peah): Do a proper size check agains the actual sample size |
| + // once the APM properly checks the sample type passed the AGC. |
|
the sun
2015/10/19 14:47:04
// TODO: Remove copying.
peah-webrtc
2015/10/26 09:09:56
This has now been refactored. Please recheck!
|
| + memcpy(&render_queue_buffer_[0], audio->mixed_low_pass_data(), |
| + (audio->num_frames_per_band() * sizeof(int16_t))); |
| + render_queue_buffer_.resize(audio->num_frames_per_band()); |
| + // TODO(peah): Refactor so that it is possible to check the |
| + // return value of Insert. Currently, that is not possible |
| + // due to the code design when the capture thread is never |
| + // started. |
| + render_signal_queue_->Insert(&render_queue_buffer_); |
| } |
| return apm_->kNoError; |
| } |
| +// Read chunks of data that were received and queued on the render side from |
| +// a queue. All the data chunks are buffered into the farend signal of the AGC. |
| +void GainControlImpl::ReadQueuedRenderData() { |
| + if (!is_component_enabled()) { |
| + return; |
| + } |
| + |
| + while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
| + for (int i = 0; i < num_handles(); i++) { |
| + Handle* my_handle = static_cast<Handle*>(handle(i)); |
| + (void)WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[0], |
| + capture_queue_buffer_.size()); |
| + } |
| + } |
| +} |
| + |
| int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
| if (!is_component_enabled()) { |
| return apm_->kNoError; |
| @@ -340,4 +374,8 @@ int GainControlImpl::GetHandleError(void* handle) const { |
| assert(handle != NULL); |
| return apm_->kUnspecifiedError; |
| } |
| + |
| +bool GainControlImpl::RenderQueueItemVerifier(const std::vector<int16_t>& v) { |
| + return (v.size() == kNumSamplesPerFrameToBuffer); |
| +} |
| } // namespace webrtc |