OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/media_stream_audio_processor.h" | 5 #include "content/renderer/media/media_stream_audio_processor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // True when |destination_| contains the data to be returned by the next call | 316 // True when |destination_| contains the data to be returned by the next call |
317 // to Consume(). Only used when the FIFO is disabled. | 317 // to Consume(). Only used when the FIFO is disabled. |
318 bool data_available_; | 318 bool data_available_; |
319 }; | 319 }; |
320 | 320 |
321 MediaStreamAudioProcessor::MediaStreamAudioProcessor( | 321 MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
322 const blink::WebMediaConstraints& constraints, | 322 const blink::WebMediaConstraints& constraints, |
323 const MediaStreamDevice::AudioDeviceParameters& input_params, | 323 const MediaStreamDevice::AudioDeviceParameters& input_params, |
324 WebRtcPlayoutDataSource* playout_data_source) | 324 WebRtcPlayoutDataSource* playout_data_source) |
325 : render_delay_ms_(0), | 325 : render_delay_ms_(0), |
| 326 has_echo_cancellation_(false), |
326 playout_data_source_(playout_data_source), | 327 playout_data_source_(playout_data_source), |
327 main_thread_runner_(base::ThreadTaskRunnerHandle::Get()), | 328 main_thread_runner_(base::ThreadTaskRunnerHandle::Get()), |
328 audio_mirroring_(false), | 329 audio_mirroring_(false), |
329 typing_detected_(false), | 330 typing_detected_(false), |
330 stopped_(false) { | 331 stopped_(false) { |
331 DCHECK(main_thread_runner_); | 332 DCHECK(main_thread_runner_); |
332 capture_thread_checker_.DetachFromThread(); | 333 capture_thread_checker_.DetachFromThread(); |
333 render_thread_checker_.DetachFromThread(); | 334 render_thread_checker_.DetachFromThread(); |
334 InitializeAudioProcessingModule(constraints, input_params); | 335 InitializeAudioProcessingModule(constraints, input_params); |
335 | 336 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 else | 480 else |
480 file.Close(); | 481 file.Close(); |
481 } | 482 } |
482 | 483 |
483 void MediaStreamAudioProcessor::OnDisableAecDump() { | 484 void MediaStreamAudioProcessor::OnDisableAecDump() { |
484 DCHECK(main_thread_runner_->BelongsToCurrentThread()); | 485 DCHECK(main_thread_runner_->BelongsToCurrentThread()); |
485 if (audio_processing_) | 486 if (audio_processing_) |
486 StopEchoCancellationDump(audio_processing_.get()); | 487 StopEchoCancellationDump(audio_processing_.get()); |
487 } | 488 } |
488 | 489 |
| 490 void MediaStreamAudioProcessor::OnAec3Enable(bool enable) { |
| 491 DCHECK(main_thread_runner_->BelongsToCurrentThread()); |
| 492 if (override_aec3_ == enable) |
| 493 return; |
| 494 |
| 495 override_aec3_ = enable; |
| 496 if (!has_echo_cancellation_) |
| 497 return; |
| 498 |
| 499 auto apm_config = audio_processing_->GetConfig(); |
| 500 if (apm_config.echo_canceller3.enabled == enable) |
| 501 return; |
| 502 |
| 503 apm_config.echo_canceller3.enabled = enable; |
| 504 audio_processing_->ApplyConfig(apm_config); |
| 505 DCHECK(echo_information_); |
| 506 echo_information_.reset(new EchoInformation()); |
| 507 } |
| 508 |
489 void MediaStreamAudioProcessor::OnIpcClosing() { | 509 void MediaStreamAudioProcessor::OnIpcClosing() { |
490 DCHECK(main_thread_runner_->BelongsToCurrentThread()); | 510 DCHECK(main_thread_runner_->BelongsToCurrentThread()); |
491 aec_dump_message_filter_ = NULL; | 511 aec_dump_message_filter_ = NULL; |
492 } | 512 } |
493 | 513 |
494 // static | 514 // static |
495 bool MediaStreamAudioProcessor::WouldModifyAudio( | 515 bool MediaStreamAudioProcessor::WouldModifyAudio( |
496 const blink::WebMediaConstraints& constraints, | 516 const blink::WebMediaConstraints& constraints, |
497 int effects_flags) { | 517 int effects_flags) { |
498 // Note: This method should by kept in-sync with any changes to the logic in | 518 // Note: This method should by kept in-sync with any changes to the logic in |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 609 |
590 MediaAudioConstraints audio_constraints(constraints, input_params.effects); | 610 MediaAudioConstraints audio_constraints(constraints, input_params.effects); |
591 | 611 |
592 // Note: The audio mirroring constraint (i.e., swap left and right channels) | 612 // Note: The audio mirroring constraint (i.e., swap left and right channels) |
593 // is handled within this MediaStreamAudioProcessor and does not, by itself, | 613 // is handled within this MediaStreamAudioProcessor and does not, by itself, |
594 // require webrtc::AudioProcessing. | 614 // require webrtc::AudioProcessing. |
595 audio_mirroring_ = audio_constraints.GetGoogAudioMirroring(); | 615 audio_mirroring_ = audio_constraints.GetGoogAudioMirroring(); |
596 | 616 |
597 const bool echo_cancellation = | 617 const bool echo_cancellation = |
598 audio_constraints.GetEchoCancellationProperty(); | 618 audio_constraints.GetEchoCancellationProperty(); |
| 619 has_echo_cancellation_ = echo_cancellation; |
599 const bool goog_agc = audio_constraints.GetGoogAutoGainControl(); | 620 const bool goog_agc = audio_constraints.GetGoogAutoGainControl(); |
600 | 621 |
601 #if defined(OS_ANDROID) | 622 #if defined(OS_ANDROID) |
602 const bool goog_experimental_aec = false; | 623 const bool goog_experimental_aec = false; |
603 const bool goog_typing_detection = false; | 624 const bool goog_typing_detection = false; |
604 #else | 625 #else |
605 const bool goog_experimental_aec = | 626 const bool goog_experimental_aec = |
606 audio_constraints.GetGoogExperimentalEchoCancellation(); | 627 audio_constraints.GetGoogExperimentalEchoCancellation(); |
607 const bool goog_typing_detection = | 628 const bool goog_typing_detection = |
608 audio_constraints.GetGoogTypingNoiseDetection(); | 629 audio_constraints.GetGoogTypingNoiseDetection(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 playout_data_source_->AddPlayoutSink(this); | 693 playout_data_source_->AddPlayoutSink(this); |
673 } | 694 } |
674 | 695 |
675 if (echo_cancellation) { | 696 if (echo_cancellation) { |
676 EnableEchoCancellation(audio_processing_.get()); | 697 EnableEchoCancellation(audio_processing_.get()); |
677 | 698 |
678 // Prepare for logging echo information. If there are data remaining in | 699 // Prepare for logging echo information. If there are data remaining in |
679 // |echo_information_| we simply discard it. | 700 // |echo_information_| we simply discard it. |
680 echo_information_.reset(new EchoInformation()); | 701 echo_information_.reset(new EchoInformation()); |
681 | 702 |
682 apm_config.echo_canceller3.enabled = | 703 apm_config.echo_canceller3.enabled = override_aec3_.value_or( |
683 base::FeatureList::IsEnabled(features::kWebRtcUseEchoCanceller3); | 704 base::FeatureList::IsEnabled(features::kWebRtcUseEchoCanceller3)); |
684 } else { | 705 } else { |
685 apm_config.echo_canceller3.enabled = false; | 706 apm_config.echo_canceller3.enabled = false; |
686 } | 707 } |
687 | 708 |
688 if (goog_ns) { | 709 if (goog_ns) { |
689 // The beamforming postfilter is effective at suppressing stationary noise, | 710 // The beamforming postfilter is effective at suppressing stationary noise, |
690 // so reduce the single-channel NS aggressiveness when enabled. | 711 // so reduce the single-channel NS aggressiveness when enabled. |
691 const NoiseSuppression::Level ns_level = | 712 const NoiseSuppression::Level ns_level = |
692 config.Get<webrtc::Beamforming>().enabled ? NoiseSuppression::kLow | 713 config.Get<webrtc::Beamforming>().enabled ? NoiseSuppression::kLow |
693 : NoiseSuppression::kHigh; | 714 : NoiseSuppression::kHigh; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 0 : agc->stream_analog_level(); | 891 0 : agc->stream_analog_level(); |
871 } | 892 } |
872 | 893 |
873 void MediaStreamAudioProcessor::UpdateAecStats() { | 894 void MediaStreamAudioProcessor::UpdateAecStats() { |
874 DCHECK(main_thread_runner_->BelongsToCurrentThread()); | 895 DCHECK(main_thread_runner_->BelongsToCurrentThread()); |
875 if (echo_information_) | 896 if (echo_information_) |
876 echo_information_->UpdateAecStats(audio_processing_->echo_cancellation()); | 897 echo_information_->UpdateAecStats(audio_processing_->echo_cancellation()); |
877 } | 898 } |
878 | 899 |
879 } // namespace content | 900 } // namespace content |
OLD | NEW |