Chromium Code Reviews| 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 0de5e620ceb41dbea2bc1f50f47c8bda640cd69b..62040a4703940017a14cdf0593ff4b340b3c916b 100644 |
| --- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc |
| +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc |
| @@ -55,6 +55,9 @@ AudioProcessing::Error MapError(int err) { |
| } |
| } // namespace |
| +const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame1; |
| +const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame2; |
| + |
| EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
| CriticalSectionWrapper* crit) |
| : ProcessingComponent(), |
| @@ -68,7 +71,9 @@ EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
| stream_has_echo_(false), |
| delay_logging_enabled_(false), |
| extended_filter_enabled_(false), |
| - delay_agnostic_enabled_(false) { |
| + delay_agnostic_enabled_(false), |
| + render_queue_element_max_size_(0) { |
| + AllocateRenderQueue(); |
| } |
| EchoCancellationImpl::~EchoCancellationImpl() {} |
| @@ -85,25 +90,62 @@ int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { |
| // The ordering convention must be followed to pass to the correct AEC. |
| size_t handle_index = 0; |
| + render_queue_buffer_.resize(0); |
|
kwiberg-webrtc
2015/11/05 12:20:02
a.k.a. .clear()
peah-webrtc
2015/11/06 06:55:04
Done.
|
| for (int i = 0; i < apm_->num_output_channels(); i++) { |
| for (int j = 0; j < audio->num_channels(); j++) { |
| Handle* my_handle = static_cast<Handle*>(handle(handle_index)); |
| - err = WebRtcAec_BufferFarend( |
| - my_handle, |
| - audio->split_bands_const_f(j)[kBand0To8kHz], |
| + // Retrieve any error code produced by the buffering of the farend |
| + // signal |
| + err = WebRtcAec_GetBufferFarendError( |
| + my_handle, audio->split_bands_const_f(j)[kBand0To8kHz], |
| audio->num_frames_per_band()); |
| if (err != apm_->kNoError) { |
| return MapError(err); // TODO(ajm): warning possible? |
| } |
| - handle_index++; |
| + // Buffer the samples in the render queue. |
| + render_queue_buffer_.insert(render_queue_buffer_.end(), |
| + audio->split_bands_const_f(j)[kBand0To8kHz], |
| + (audio->split_bands_const_f(j)[kBand0To8kHz] + |
| + 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_); |
|
hlundin-webrtc
2015/11/05 12:45:26
Drop (void).
peah-webrtc
2015/11/06 06:55:04
I think it is needed, as the Insert is annotated w
hlundin-webrtc
2015/11/06 07:05:13
Acknowledged. I didn't know you had annotated Inse
|
| + |
| 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 AEC. |
| +void EchoCancellationImpl::ReadQueuedRenderData() { |
| + if (!is_component_enabled()) { |
| + return; |
| + } |
| + |
| + while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
| + size_t handle_index = 0; |
| + int buffer_index = 0; |
| + const int num_frames_per_band = |
| + capture_queue_buffer_.size() / |
| + (apm_->num_output_channels() * apm_->num_reverse_channels()); |
| + for (int i = 0; i < apm_->num_output_channels(); i++) { |
| + for (int j = 0; j < apm_->num_reverse_channels(); j++) { |
| + Handle* my_handle = static_cast<Handle*>(handle(handle_index)); |
| + (void)WebRtcAec_BufferFarend(my_handle, |
|
hlundin-webrtc
2015/11/05 12:45:26
Drop (void).
peah-webrtc
2015/11/06 06:55:04
Done.
|
| + &capture_queue_buffer_[buffer_index], |
| + num_frames_per_band); |
| + |
| + buffer_index += num_frames_per_band; |
| + handle_index++; |
| + } |
| + } |
| + } |
| +} |
| + |
| int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
| if (!is_component_enabled()) { |
| return apm_->kNoError; |
| @@ -333,9 +375,38 @@ int EchoCancellationImpl::Initialize() { |
| return err; |
| } |
| + AllocateRenderQueue(); |
| + |
| return apm_->kNoError; |
| } |
| +void EchoCancellationImpl::AllocateRenderQueue() { |
| + const size_t max_frame_size = std::max(kAllowedValuesOfSamplesPerFrame1, |
| + kAllowedValuesOfSamplesPerFrame2); |
| + |
| + const size_t new_render_queue_element_max_size = |
| + std::max(1UL, max_frame_size * num_handles_required()); |
|
hlundin-webrtc
2015/11/05 12:45:26
Is 1UL always the same size as size_t, for the pla
peah-webrtc
2015/11/06 06:55:04
Great! I got a trybot fail for this, so I'll also
|
| + |
| + // Reallocate the queue if the queue item size is too small to fit the |
| + // data to put in the queue. |
| + if (new_render_queue_element_max_size > render_queue_element_max_size_) { |
| + render_queue_element_max_size_ = new_render_queue_element_max_size; |
| + |
| + std::vector<float> template_queue_element(render_queue_element_max_size_); |
| + |
| + render_signal_queue_.reset( |
| + new SwapQueue<std::vector<float>, AecRenderQueueItemVerifier>( |
| + kMaxNumFramesToBuffer, |
| + AecRenderQueueItemVerifier(render_queue_element_max_size_), |
| + template_queue_element)); |
| + } else { |
| + render_signal_queue_->Clear(); |
| + } |
| + |
| + render_queue_buffer_.resize(new_render_queue_element_max_size); |
| + capture_queue_buffer_.resize(new_render_queue_element_max_size); |
| +} |
| + |
| void EchoCancellationImpl::SetExtraOptions(const Config& config) { |
| extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; |
| delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; |
| @@ -368,7 +439,6 @@ int EchoCancellationImpl::ConfigureHandle(void* handle) const { |
| config.nlpMode = MapSetting(suppression_level_); |
| config.skewMode = drift_compensation_enabled_; |
| config.delay_logging = delay_logging_enabled_; |
| - |
|
hlundin-webrtc
2015/11/05 12:45:26
Why?
peah-webrtc
2015/11/06 06:55:04
Done.
|
| WebRtcAec_enable_extended_filter( |
| WebRtcAec_aec_core(static_cast<Handle*>(handle)), |
| extended_filter_enabled_ ? 1 : 0); |
| @@ -387,4 +457,5 @@ int EchoCancellationImpl::GetHandleError(void* handle) const { |
| assert(handle != NULL); |
| return AudioProcessing::kUnspecifiedError; |
| } |
| + |
|
hlundin-webrtc
2015/11/05 12:45:25
Why?
peah-webrtc
2015/11/06 06:55:04
Done.
|
| } // namespace webrtc |