OLD | NEW |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return AudioProcessing::kBadParameterError; | 46 return AudioProcessing::kBadParameterError; |
47 case AEC_BAD_PARAMETER_WARNING: | 47 case AEC_BAD_PARAMETER_WARNING: |
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 |
| 57 // Maximum length that a frame of samples can have. |
| 58 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160; |
| 59 // Maximum number of frames to buffer in the render queue. |
| 60 // TODO(peah): Decrease this once we properly handle hugely unbalanced |
| 61 // reverse and forward call numbers. |
| 62 static const size_t kMaxNumFramesToBuffer = 100; |
56 } // namespace | 63 } // namespace |
57 | 64 |
58 const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame1; | |
59 const size_t EchoCancellationImpl::kAllowedValuesOfSamplesPerFrame2; | |
60 | |
61 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, | 65 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
62 CriticalSectionWrapper* crit) | 66 CriticalSectionWrapper* crit) |
63 : ProcessingComponent(), | 67 : ProcessingComponent(), |
64 apm_(apm), | 68 apm_(apm), |
65 crit_(crit), | 69 crit_(crit), |
66 drift_compensation_enabled_(false), | 70 drift_compensation_enabled_(false), |
67 metrics_enabled_(false), | 71 metrics_enabled_(false), |
68 suppression_level_(kModerateSuppression), | 72 suppression_level_(kModerateSuppression), |
69 stream_drift_samples_(0), | 73 stream_drift_samples_(0), |
70 was_stream_drift_set_(false), | 74 was_stream_drift_set_(false), |
71 stream_has_echo_(false), | 75 stream_has_echo_(false), |
72 delay_logging_enabled_(false), | 76 delay_logging_enabled_(false), |
73 extended_filter_enabled_(false), | 77 extended_filter_enabled_(false), |
74 delay_agnostic_enabled_(false), | 78 delay_agnostic_enabled_(false), |
75 render_queue_element_max_size_(0) { | 79 render_queue_element_max_size_(0) {} |
76 AllocateRenderQueue(); | |
77 } | |
78 | 80 |
79 EchoCancellationImpl::~EchoCancellationImpl() {} | 81 EchoCancellationImpl::~EchoCancellationImpl() {} |
80 | 82 |
81 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { | 83 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { |
82 if (!is_component_enabled()) { | 84 if (!is_component_enabled()) { |
83 return apm_->kNoError; | 85 return apm_->kNoError; |
84 } | 86 } |
85 | 87 |
86 assert(audio->num_frames_per_band() <= 160); | 88 assert(audio->num_frames_per_band() <= 160); |
87 assert(audio->num_channels() == apm_->num_reverse_channels()); | 89 assert(audio->num_channels() == apm_->num_reverse_channels()); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 if (err != apm_->kNoError || !is_component_enabled()) { | 379 if (err != apm_->kNoError || !is_component_enabled()) { |
378 return err; | 380 return err; |
379 } | 381 } |
380 | 382 |
381 AllocateRenderQueue(); | 383 AllocateRenderQueue(); |
382 | 384 |
383 return apm_->kNoError; | 385 return apm_->kNoError; |
384 } | 386 } |
385 | 387 |
386 void EchoCancellationImpl::AllocateRenderQueue() { | 388 void EchoCancellationImpl::AllocateRenderQueue() { |
387 const size_t max_frame_size = std::max<size_t>( | |
388 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); | |
389 | |
390 const size_t new_render_queue_element_max_size = std::max<size_t>( | 389 const size_t new_render_queue_element_max_size = std::max<size_t>( |
391 static_cast<size_t>(1), max_frame_size * num_handles_required()); | 390 static_cast<size_t>(1), |
| 391 kMaxAllowedValuesOfSamplesPerFrame * num_handles_required()); |
392 | 392 |
393 // Reallocate the queue if the queue item size is too small to fit the | 393 // Reallocate the queue if the queue item size is too small to fit the |
394 // data to put in the queue. | 394 // data to put in the queue. |
395 if (new_render_queue_element_max_size > render_queue_element_max_size_) { | 395 if (render_queue_element_max_size_ < new_render_queue_element_max_size) { |
396 render_queue_element_max_size_ = new_render_queue_element_max_size; | 396 render_queue_element_max_size_ = new_render_queue_element_max_size; |
397 | 397 |
398 std::vector<float> template_queue_element(render_queue_element_max_size_); | 398 std::vector<float> template_queue_element(render_queue_element_max_size_); |
399 | 399 |
400 render_signal_queue_.reset( | 400 render_signal_queue_.reset( |
401 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( | 401 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
402 kMaxNumFramesToBuffer, template_queue_element, | 402 kMaxNumFramesToBuffer, template_queue_element, |
403 RenderQueueItemVerifier<float>(render_queue_element_max_size_))); | 403 RenderQueueItemVerifier<float>(render_queue_element_max_size_))); |
| 404 |
| 405 render_queue_buffer_.resize(render_queue_element_max_size_); |
| 406 capture_queue_buffer_.resize(render_queue_element_max_size_); |
404 } else { | 407 } else { |
405 render_signal_queue_->Clear(); | 408 render_signal_queue_->Clear(); |
406 } | 409 } |
407 | |
408 render_queue_buffer_.resize(new_render_queue_element_max_size); | |
409 capture_queue_buffer_.resize(new_render_queue_element_max_size); | |
410 } | 410 } |
411 | 411 |
412 void EchoCancellationImpl::SetExtraOptions(const Config& config) { | 412 void EchoCancellationImpl::SetExtraOptions(const Config& config) { |
413 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; | 413 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; |
414 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; | 414 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; |
415 Configure(); | 415 Configure(); |
416 } | 416 } |
417 | 417 |
418 void* EchoCancellationImpl::CreateHandle() const { | 418 void* EchoCancellationImpl::CreateHandle() const { |
419 return WebRtcAec_Create(); | 419 return WebRtcAec_Create(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 int EchoCancellationImpl::num_handles_required() const { | 454 int EchoCancellationImpl::num_handles_required() const { |
455 return apm_->num_output_channels() * | 455 return apm_->num_output_channels() * |
456 apm_->num_reverse_channels(); | 456 apm_->num_reverse_channels(); |
457 } | 457 } |
458 | 458 |
459 int EchoCancellationImpl::GetHandleError(void* handle) const { | 459 int EchoCancellationImpl::GetHandleError(void* handle) const { |
460 assert(handle != NULL); | 460 assert(handle != NULL); |
461 return AudioProcessing::kUnspecifiedError; | 461 return AudioProcessing::kUnspecifiedError; |
462 } | 462 } |
463 } // namespace webrtc | 463 } // namespace webrtc |
OLD | NEW |