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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
61 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, | 58 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, |
62 CriticalSectionWrapper* crit) | 59 CriticalSectionWrapper* crit) |
63 : ProcessingComponent(), | 60 : ProcessingComponent(), |
64 apm_(apm), | 61 apm_(apm), |
65 crit_(crit), | 62 crit_(crit), |
66 drift_compensation_enabled_(false), | 63 drift_compensation_enabled_(false), |
67 metrics_enabled_(false), | 64 metrics_enabled_(false), |
68 suppression_level_(kModerateSuppression), | 65 suppression_level_(kModerateSuppression), |
69 stream_drift_samples_(0), | 66 stream_drift_samples_(0), |
70 was_stream_drift_set_(false), | 67 was_stream_drift_set_(false), |
71 stream_has_echo_(false), | 68 stream_has_echo_(false), |
72 delay_logging_enabled_(false), | 69 delay_logging_enabled_(false), |
73 extended_filter_enabled_(false), | 70 extended_filter_enabled_(false), |
74 delay_agnostic_enabled_(false), | 71 delay_agnostic_enabled_(false), |
75 render_queue_element_max_size_(0) { | 72 render_queue_element_max_size_(0) {} |
76 AllocateRenderQueue(); | |
77 } | |
78 | 73 |
79 EchoCancellationImpl::~EchoCancellationImpl() {} | 74 EchoCancellationImpl::~EchoCancellationImpl() {} |
80 | 75 |
81 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { | 76 int EchoCancellationImpl::ProcessRenderAudio(const AudioBuffer* audio) { |
82 if (!is_component_enabled()) { | 77 if (!is_component_enabled()) { |
83 return apm_->kNoError; | 78 return apm_->kNoError; |
84 } | 79 } |
85 | 80 |
86 assert(audio->num_frames_per_band() <= 160); | 81 assert(audio->num_frames_per_band() <= 160); |
87 assert(audio->num_channels() == apm_->num_reverse_channels()); | 82 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()) { | 372 if (err != apm_->kNoError || !is_component_enabled()) { |
378 return err; | 373 return err; |
379 } | 374 } |
380 | 375 |
381 AllocateRenderQueue(); | 376 AllocateRenderQueue(); |
382 | 377 |
383 return apm_->kNoError; | 378 return apm_->kNoError; |
384 } | 379 } |
385 | 380 |
386 void EchoCancellationImpl::AllocateRenderQueue() { | 381 void EchoCancellationImpl::AllocateRenderQueue() { |
387 const size_t max_frame_size = std::max<size_t>( | 382 const size_t max_frame_size = |
388 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); | 383 std::max<size_t>(static_cast<size_t>(kAllowedValuesOfSamplesPerFrame1), |
the sun
2015/11/17 13:44:37
It seems wasteful to me to do this at runtime. Why
peah-webrtc
2015/11/18 05:53:46
Good point!
Done.
| |
384 static_cast<size_t>(kAllowedValuesOfSamplesPerFrame2)); | |
389 | 385 |
390 const size_t new_render_queue_element_max_size = std::max<size_t>( | 386 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()); | 387 static_cast<size_t>(1), max_frame_size * num_handles_required()); |
392 | 388 |
393 // Reallocate the queue if the queue item size is too small to fit the | 389 // Reallocate the queue if the queue item size is too small to fit the |
394 // data to put in the queue. | 390 // data to put in the queue. |
395 if (new_render_queue_element_max_size > render_queue_element_max_size_) { | 391 if (new_render_queue_element_max_size > render_queue_element_max_size_) { |
the sun
2015/11/17 13:44:37
super nit: it's a little nicer to keep the operand
peah-webrtc
2015/11/18 05:53:46
Agree. And the comparison is also more readable in
| |
396 render_queue_element_max_size_ = new_render_queue_element_max_size; | 392 render_queue_element_max_size_ = new_render_queue_element_max_size; |
397 | 393 |
398 std::vector<float> template_queue_element(render_queue_element_max_size_); | 394 std::vector<float> template_queue_element(render_queue_element_max_size_); |
399 | 395 |
400 render_signal_queue_.reset( | 396 render_signal_queue_.reset( |
401 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( | 397 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
402 kMaxNumFramesToBuffer, template_queue_element, | 398 kMaxNumFramesToBuffer, template_queue_element, |
the sun
2015/11/17 13:44:37
Move kMaxNumFramesToBuffer into the anonymous name
peah-webrtc
2015/11/18 05:53:46
Done.
| |
403 RenderQueueItemVerifier<float>(render_queue_element_max_size_))); | 399 RenderQueueItemVerifier<float>(render_queue_element_max_size_))); |
400 | |
401 render_queue_buffer_.resize(render_queue_element_max_size_); | |
402 capture_queue_buffer_.resize(render_queue_element_max_size_); | |
404 } else { | 403 } else { |
405 render_signal_queue_->Clear(); | 404 render_signal_queue_->Clear(); |
406 } | 405 } |
407 | |
408 render_queue_buffer_.resize(new_render_queue_element_max_size); | |
409 capture_queue_buffer_.resize(new_render_queue_element_max_size); | |
410 } | 406 } |
411 | 407 |
412 void EchoCancellationImpl::SetExtraOptions(const Config& config) { | 408 void EchoCancellationImpl::SetExtraOptions(const Config& config) { |
413 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; | 409 extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled; |
414 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; | 410 delay_agnostic_enabled_ = config.Get<DelayAgnostic>().enabled; |
415 Configure(); | 411 Configure(); |
416 } | 412 } |
417 | 413 |
418 void* EchoCancellationImpl::CreateHandle() const { | 414 void* EchoCancellationImpl::CreateHandle() const { |
419 return WebRtcAec_Create(); | 415 return WebRtcAec_Create(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 int EchoCancellationImpl::num_handles_required() const { | 450 int EchoCancellationImpl::num_handles_required() const { |
455 return apm_->num_output_channels() * | 451 return apm_->num_output_channels() * |
456 apm_->num_reverse_channels(); | 452 apm_->num_reverse_channels(); |
457 } | 453 } |
458 | 454 |
459 int EchoCancellationImpl::GetHandleError(void* handle) const { | 455 int EchoCancellationImpl::GetHandleError(void* handle) const { |
460 assert(handle != NULL); | 456 assert(handle != NULL); |
461 return AudioProcessing::kUnspecifiedError; | 457 return AudioProcessing::kUnspecifiedError; |
462 } | 458 } |
463 } // namespace webrtc | 459 } // namespace webrtc |
OLD | NEW |