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

Side by Side Diff: webrtc/modules/audio_processing/echo_cancellation_impl.cc

Issue 1410833002: Lock scheme #4: Introduced the render sample queue for the aec and aecm (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@aec_error_report_CL
Patch Set: Changes in response to latest 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return AudioProcessing::kBadStreamParameterWarning; 48 return AudioProcessing::kBadStreamParameterWarning;
49 default: 49 default:
50 // AEC_UNSPECIFIED_ERROR 50 // AEC_UNSPECIFIED_ERROR
51 // AEC_UNINITIALIZED_ERROR 51 // AEC_UNINITIALIZED_ERROR
52 // AEC_NULL_POINTER_ERROR 52 // AEC_NULL_POINTER_ERROR
53 return AudioProcessing::kUnspecifiedError; 53 return AudioProcessing::kUnspecifiedError;
54 } 54 }
55 } 55 }
56 } // namespace 56 } // namespace
57 57
58 const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame1;
59 const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame2;
60
58 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, 61 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm,
59 CriticalSectionWrapper* crit) 62 CriticalSectionWrapper* crit)
60 : ProcessingComponent(), 63 : ProcessingComponent(),
61 apm_(apm), 64 apm_(apm),
62 crit_(crit), 65 crit_(crit),
63 drift_compensation_enabled_(false), 66 drift_compensation_enabled_(false),
64 metrics_enabled_(false), 67 metrics_enabled_(false),
65 suppression_level_(kModerateSuppression), 68 suppression_level_(kModerateSuppression),
66 stream_drift_samples_(0), 69 stream_drift_samples_(0),
67 was_stream_drift_set_(false), 70 was_stream_drift_set_(false),
68 stream_has_echo_(false), 71 stream_has_echo_(false),
69 delay_logging_enabled_(false), 72 delay_logging_enabled_(false),
70 extended_filter_enabled_(false), 73 extended_filter_enabled_(false),
71 delay_agnostic_enabled_(false) { 74 delay_agnostic_enabled_(false),
75 render_queue_element_max_size_(0) {
76 AllocateRenderQueue();
72 } 77 }
73 78
74 EchoCancellationImpl::~EchoCancellationImpl() {} 79 EchoCancellationImpl::~EchoCancellationImpl() {}
75 80
76 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { 81 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) {
77 if (!is_component_enabled()) { 82 if (!is_component_enabled()) {
78 return apm_->kNoError; 83 return apm_->kNoError;
79 } 84 }
80 85
81 assert(audio->num_frames_per_band() <= 160); 86 assert(audio->num_frames_per_band() <= 160);
82 assert(audio->num_channels() == apm_->num_reverse_channels()); 87 assert(audio->num_channels() == apm_->num_reverse_channels());
83 88
84 int err = apm_->kNoError; 89 int err = apm_->kNoError;
85 90
86 // The ordering convention must be followed to pass to the correct AEC. 91 // The ordering convention must be followed to pass to the correct AEC.
87 size_t handle_index = 0; 92 size_t handle_index = 0;
93 render_queue_buffer_.clear();
88 for (int i = 0; i < apm_->num_output_channels(); i++) { 94 for (int i = 0; i < apm_->num_output_channels(); i++) {
89 for (int j = 0; j < audio->num_channels(); j++) { 95 for (int j = 0; j < audio->num_channels(); j++) {
90 Handle* my_handle = static_cast<Handle*>(handle(handle_index)); 96 Handle* my_handle = static_cast<Handle*>(handle(handle_index));
91 err = WebRtcAec_BufferFarend( 97 // Retrieve any error code produced by the buffering of the farend
92 my_handle, 98 // signal
93 audio->split_bands_const_f(j)[kBand0To8kHz], 99 err = WebRtcAec_GetBufferFarendError(
100 my_handle, audio->split_bands_const_f(j)[kBand0To8kHz],
94 audio->num_frames_per_band()); 101 audio->num_frames_per_band());
95 102
96 if (err != apm_->kNoError) { 103 if (err != apm_->kNoError) {
97 return MapError(err); // TODO(ajm): warning possible? 104 return MapError(err); // TODO(ajm): warning possible?
98 } 105 }
99 106
100 handle_index++; 107 // Buffer the samples in the render queue.
108 render_queue_buffer_.insert(render_queue_buffer_.end(),
109 audio->split_bands_const_f(j)[kBand0To8kHz],
110 (audio->split_bands_const_f(j)[kBand0To8kHz] +
111 audio->num_frames_per_band()));
101 } 112 }
102 } 113 }
103 114
115 // Check of success is temporarily disabled as it breaks a unit test.
116 // TODO(peah): Will be fixed in the next CL.
117 (void)render_signal_queue_->Insert(&render_queue_buffer_);
118
104 return apm_->kNoError; 119 return apm_->kNoError;
105 } 120 }
106 121
122 // Read chunks of data that were received and queued on the render side from
123 // a queue. All the data chunks are buffered into the farend signal of the AEC.
124 void EchoCancellationImpl::ReadQueuedRenderData() {
125 if (!is_component_enabled()) {
126 return;
127 }
128
129 while (render_signal_queue_->Remove(&capture_queue_buffer_)) {
130 size_t handle_index = 0;
131 int buffer_index = 0;
132 const int num_frames_per_band =
133 capture_queue_buffer_.size() /
134 (apm_->num_output_channels() * apm_->num_reverse_channels());
135 for (int i = 0; i < apm_->num_output_channels(); i++) {
136 for (int j = 0; j < apm_->num_reverse_channels(); j++) {
137 Handle* my_handle = static_cast<Handle*>(handle(handle_index));
138 WebRtcAec_BufferFarend(my_handle, &capture_queue_buffer_[buffer_index],
139 num_frames_per_band);
140
141 buffer_index += num_frames_per_band;
142 handle_index++;
143 }
144 }
145 }
146 }
147
107 int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { 148 int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) {
108 if (!is_component_enabled()) { 149 if (!is_component_enabled()) {
109 return apm_->kNoError; 150 return apm_->kNoError;
110 } 151 }
111 152
112 if (!apm_->was_stream_delay_set()) { 153 if (!apm_->was_stream_delay_set()) {
113 return apm_->kStreamParameterNotSetError; 154 return apm_->kStreamParameterNotSetError;
114 } 155 }
115 156
116 if (drift_compensation_enabled_ && !was_stream_drift_set_) { 157 if (drift_compensation_enabled_ && !was_stream_drift_set_) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 Handle* my_handle = static_cast<Handle*>(handle(0)); 367 Handle* my_handle = static_cast<Handle*>(handle(0));
327 return WebRtcAec_aec_core(my_handle); 368 return WebRtcAec_aec_core(my_handle);
328 } 369 }
329 370
330 int EchoCancellationImpl::Initialize() { 371 int EchoCancellationImpl::Initialize() {
331 int err = ProcessingComponent::Initialize(); 372 int err = ProcessingComponent::Initialize();
332 if (err != apm_->kNoError || !is_component_enabled()) { 373 if (err != apm_->kNoError || !is_component_enabled()) {
333 return err; 374 return err;
334 } 375 }
335 376
377 AllocateRenderQueue();
378
336 return apm_->kNoError; 379 return apm_->kNoError;
337 } 380 }
338 381
382 void EchoCancellationImpl::AllocateRenderQueue() {
383 const size_t max_frame_size = std::max<size_t>(
384 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2);
385
386 const size_t new_render_queue_element_max_size = std::max<size_t>(
387 static_cast<size_t>(1), max_frame_size * num_handles_required());
388
389 // Reallocate the queue if the queue item size is too small to fit the
390 // data to put in the queue.
391 if (new_render_queue_element_max_size > render_queue_element_max_size_) {
392 render_queue_element_max_size_ = new_render_queue_element_max_size;
393
394 std::vector<float> template_queue_element(render_queue_element_max_size_);
395
396 render_signal_queue_.reset(
397 new SwapQueue<std::vector<float>, AecRenderQueueItemVerifier>(
398 kMaxNumFramesToBuffer,
399 AecRenderQueueItemVerifier(render_queue_element_max_size_),
400 template_queue_element));
401 } else {
402 render_signal_queue_->Clear();
403 }
404
405 render_queue_buffer_.resize(new_render_queue_element_max_size);
406 capture_queue_buffer_.resize(new_render_queue_element_max_size);
407 }
408
339 void EchoCancellationImpl::SetExtraOptions(const Config& config) { 409 void EchoCancellationImpl::SetExtraOptions(const Config& config) {
340 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; 410 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled;
341 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; 411 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled;
342 Configure(); 412 Configure();
343 } 413 }
344 414
345 void* EchoCancellationImpl::CreateHandle() const { 415 void* EchoCancellationImpl::CreateHandle() const {
346 return WebRtcAec_Create(); 416 return WebRtcAec_Create();
347 } 417 }
348 418
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 int EchoCancellationImpl::num_handles_required() const { 451 int EchoCancellationImpl::num_handles_required() const {
382 return apm_->num_output_channels() * 452 return apm_->num_output_channels() *
383 apm_->num_reverse_channels(); 453 apm_->num_reverse_channels();
384 } 454 }
385 455
386 int EchoCancellationImpl::GetHandleError(void* handle) const { 456 int EchoCancellationImpl::GetHandleError(void* handle) const {
387 assert(handle != NULL); 457 assert(handle != NULL);
388 return AudioProcessing::kUnspecifiedError; 458 return AudioProcessing::kUnspecifiedError;
389 } 459 }
390 } // namespace webrtc 460 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698