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

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: Merge from other CLs in the list 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_.resize(0);
kwiberg-webrtc 2015/11/05 12:20:02 a.k.a. .clear()
peah-webrtc 2015/11/06 06:55:04 Done.
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_);
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
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 (void)WebRtcAec_BufferFarend(my_handle,
hlundin-webrtc 2015/11/05 12:45:26 Drop (void).
peah-webrtc 2015/11/06 06:55:04 Done.
139 &capture_queue_buffer_[buffer_index],
140 num_frames_per_band);
141
142 buffer_index += num_frames_per_band;
143 handle_index++;
144 }
145 }
146 }
147 }
148
107 int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) { 149 int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio) {
108 if (!is_component_enabled()) { 150 if (!is_component_enabled()) {
109 return apm_->kNoError; 151 return apm_->kNoError;
110 } 152 }
111 153
112 if (!apm_->was_stream_delay_set()) { 154 if (!apm_->was_stream_delay_set()) {
113 return apm_->kStreamParameterNotSetError; 155 return apm_->kStreamParameterNotSetError;
114 } 156 }
115 157
116 if (drift_compensation_enabled_ && !was_stream_drift_set_) { 158 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)); 368 Handle* my_handle = static_cast<Handle*>(handle(0));
327 return WebRtcAec_aec_core(my_handle); 369 return WebRtcAec_aec_core(my_handle);
328 } 370 }
329 371
330 int EchoCancellationImpl::Initialize() { 372 int EchoCancellationImpl::Initialize() {
331 int err = ProcessingComponent::Initialize(); 373 int err = ProcessingComponent::Initialize();
332 if (err != apm_->kNoError || !is_component_enabled()) { 374 if (err != apm_->kNoError || !is_component_enabled()) {
333 return err; 375 return err;
334 } 376 }
335 377
378 AllocateRenderQueue();
379
336 return apm_->kNoError; 380 return apm_->kNoError;
337 } 381 }
338 382
383 void EchoCancellationImpl::AllocateRenderQueue() {
384 const size_t max_frame_size = std::max(kAllowedValuesOfSamplesPerFrame1,
385 kAllowedValuesOfSamplesPerFrame2);
386
387 const size_t new_render_queue_element_max_size =
388 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
389
390 // Reallocate the queue if the queue item size is too small to fit the
391 // data to put in the queue.
392 if (new_render_queue_element_max_size > render_queue_element_max_size_) {
393 render_queue_element_max_size_ = new_render_queue_element_max_size;
394
395 std::vector<float> template_queue_element(render_queue_element_max_size_);
396
397 render_signal_queue_.reset(
398 new SwapQueue<std::vector<float>, AecRenderQueueItemVerifier>(
399 kMaxNumFramesToBuffer,
400 AecRenderQueueItemVerifier(render_queue_element_max_size_),
401 template_queue_element));
402 } else {
403 render_signal_queue_->Clear();
404 }
405
406 render_queue_buffer_.resize(new_render_queue_element_max_size);
407 capture_queue_buffer_.resize(new_render_queue_element_max_size);
408 }
409
339 void EchoCancellationImpl::SetExtraOptions(const Config& config) { 410 void EchoCancellationImpl::SetExtraOptions(const Config& config) {
340 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; 411 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled;
341 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; 412 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled;
342 Configure(); 413 Configure();
343 } 414 }
344 415
345 void* EchoCancellationImpl::CreateHandle() const { 416 void* EchoCancellationImpl::CreateHandle() const {
346 return WebRtcAec_Create(); 417 return WebRtcAec_Create();
347 } 418 }
348 419
(...skipping 12 matching lines...) Expand all
361 48000); 432 48000);
362 } 433 }
363 434
364 int EchoCancellationImpl::ConfigureHandle(void* handle) const { 435 int EchoCancellationImpl::ConfigureHandle(void* handle) const {
365 assert(handle != NULL); 436 assert(handle != NULL);
366 AecConfig config; 437 AecConfig config;
367 config.metricsMode = metrics_enabled_; 438 config.metricsMode = metrics_enabled_;
368 config.nlpMode = MapSetting(suppression_level_); 439 config.nlpMode = MapSetting(suppression_level_);
369 config.skewMode = drift_compensation_enabled_; 440 config.skewMode = drift_compensation_enabled_;
370 config.delay_logging = delay_logging_enabled_; 441 config.delay_logging = delay_logging_enabled_;
371
hlundin-webrtc 2015/11/05 12:45:26 Why?
peah-webrtc 2015/11/06 06:55:04 Done.
372 WebRtcAec_enable_extended_filter( 442 WebRtcAec_enable_extended_filter(
373 WebRtcAec_aec_core(static_cast<Handle*>(handle)), 443 WebRtcAec_aec_core(static_cast<Handle*>(handle)),
374 extended_filter_enabled_ ? 1 : 0); 444 extended_filter_enabled_ ? 1 : 0);
375 WebRtcAec_enable_delay_agnostic( 445 WebRtcAec_enable_delay_agnostic(
376 WebRtcAec_aec_core(static_cast<Handle*>(handle)), 446 WebRtcAec_aec_core(static_cast<Handle*>(handle)),
377 delay_agnostic_enabled_ ? 1 : 0); 447 delay_agnostic_enabled_ ? 1 : 0);
378 return WebRtcAec_set_config(static_cast<Handle*>(handle), config); 448 return WebRtcAec_set_config(static_cast<Handle*>(handle), config);
379 } 449 }
380 450
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 }
460
hlundin-webrtc 2015/11/05 12:45:25 Why?
peah-webrtc 2015/11/06 06:55:04 Done.
390 } // namespace webrtc 461 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698