| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 DCHECK(main_thread_checker_.CalledOnValidThread()); | 442 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 443 if (audio_processing_) | 443 if (audio_processing_) |
| 444 StopEchoCancellationDump(audio_processing_.get()); | 444 StopEchoCancellationDump(audio_processing_.get()); |
| 445 } | 445 } |
| 446 | 446 |
| 447 void MediaStreamAudioProcessor::OnIpcClosing() { | 447 void MediaStreamAudioProcessor::OnIpcClosing() { |
| 448 DCHECK(main_thread_checker_.CalledOnValidThread()); | 448 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 449 aec_dump_message_filter_ = NULL; | 449 aec_dump_message_filter_ = NULL; |
| 450 } | 450 } |
| 451 | 451 |
| 452 // static |
| 453 bool MediaStreamAudioProcessor::WouldModifyAudio( |
| 454 const blink::WebMediaConstraints& constraints, |
| 455 int effects_flags) { |
| 456 // Note: This method should by kept in-sync with any changes to the logic in |
| 457 // MediaStreamAudioProcessor::InitializeAudioProcessingModule(). |
| 458 |
| 459 const MediaAudioConstraints audio_constraints(constraints, effects_flags); |
| 460 |
| 461 if (audio_constraints.GetGoogAudioMirroring()) |
| 462 return true; |
| 463 |
| 464 #if !defined(OS_IOS) |
| 465 if (audio_constraints.GetEchoCancellationProperty() || |
| 466 audio_constraints.GetGoogAutoGainControl()) { |
| 467 return true; |
| 468 } |
| 469 #endif |
| 470 |
| 471 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 472 if (audio_constraints.GetGoogExperimentalEchoCancellation() || |
| 473 audio_constraints.GetGoogTypingNoiseDetection()) { |
| 474 return true; |
| 475 } |
| 476 #endif |
| 477 |
| 478 if (audio_constraints.GetGoogNoiseSuppression() || |
| 479 audio_constraints.GetGoogExperimentalNoiseSuppression() || |
| 480 audio_constraints.GetGoogBeamforming() || |
| 481 audio_constraints.GetGoogHighpassFilter()) { |
| 482 return true; |
| 483 } |
| 484 |
| 485 return false; |
| 486 } |
| 487 |
| 452 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, | 488 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
| 453 int sample_rate, | 489 int sample_rate, |
| 454 int audio_delay_milliseconds) { | 490 int audio_delay_milliseconds) { |
| 455 DCHECK(render_thread_checker_.CalledOnValidThread()); | 491 DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 456 #if defined(OS_ANDROID) | 492 #if defined(OS_ANDROID) |
| 457 DCHECK(audio_processing_->echo_control_mobile()->is_enabled()); | 493 DCHECK(audio_processing_->echo_control_mobile()->is_enabled()); |
| 458 DCHECK(!audio_processing_->echo_cancellation()->is_enabled()); | 494 DCHECK(!audio_processing_->echo_cancellation()->is_enabled()); |
| 459 #else | 495 #else |
| 460 DCHECK(!audio_processing_->echo_control_mobile()->is_enabled()); | 496 DCHECK(!audio_processing_->echo_control_mobile()->is_enabled()); |
| 461 DCHECK(audio_processing_->echo_cancellation()->is_enabled()); | 497 DCHECK(audio_processing_->echo_cancellation()->is_enabled()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 540 } |
| 505 | 541 |
| 506 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( | 542 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
| 507 const blink::WebMediaConstraints& constraints, | 543 const blink::WebMediaConstraints& constraints, |
| 508 const MediaStreamDevice::AudioDeviceParameters& input_params) { | 544 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
| 509 DCHECK(main_thread_checker_.CalledOnValidThread()); | 545 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 510 DCHECK(!audio_processing_); | 546 DCHECK(!audio_processing_); |
| 511 | 547 |
| 512 MediaAudioConstraints audio_constraints(constraints, input_params.effects); | 548 MediaAudioConstraints audio_constraints(constraints, input_params.effects); |
| 513 | 549 |
| 514 // Audio mirroring can be enabled even though audio processing is otherwise | 550 // Note: The audio mirroring constraint (i.e., swap left and right channels) |
| 515 // disabled. | 551 // is handled within this MediaStreamAudioProcessor and does not, by itself, |
| 552 // require webrtc::AudioProcessing. |
| 516 audio_mirroring_ = audio_constraints.GetGoogAudioMirroring(); | 553 audio_mirroring_ = audio_constraints.GetGoogAudioMirroring(); |
| 517 | 554 |
| 518 const bool echo_cancellation = | 555 const bool echo_cancellation = |
| 519 audio_constraints.GetEchoCancellationProperty(); | 556 audio_constraints.GetEchoCancellationProperty(); |
| 520 const bool goog_agc = audio_constraints.GetGoogAutoGainControl(); | 557 const bool goog_agc = audio_constraints.GetGoogAutoGainControl(); |
| 521 | 558 |
| 522 #if defined(OS_ANDROID) | 559 #if defined(OS_ANDROID) |
| 523 const bool goog_experimental_aec = false; | 560 const bool goog_experimental_aec = false; |
| 524 const bool goog_typing_detection = false; | 561 const bool goog_typing_detection = false; |
| 525 #else | 562 #else |
| 526 const bool goog_experimental_aec = | 563 const bool goog_experimental_aec = |
| 527 audio_constraints.GetGoogExperimentalEchoCancellation(); | 564 audio_constraints.GetGoogExperimentalEchoCancellation(); |
| 528 const bool goog_typing_detection = | 565 const bool goog_typing_detection = |
| 529 audio_constraints.GetGoogTypingNoiseDetection(); | 566 audio_constraints.GetGoogTypingNoiseDetection(); |
| 530 #endif | 567 #endif |
| 531 | 568 |
| 532 const bool goog_ns = audio_constraints.GetGoogNoiseSuppression(); | 569 const bool goog_ns = audio_constraints.GetGoogNoiseSuppression(); |
| 533 const bool goog_experimental_ns = | 570 const bool goog_experimental_ns = |
| 534 audio_constraints.GetGoogExperimentalNoiseSuppression(); | 571 audio_constraints.GetGoogExperimentalNoiseSuppression(); |
| 535 const bool goog_beamforming = audio_constraints.GetGoogBeamforming(); | 572 const bool goog_beamforming = audio_constraints.GetGoogBeamforming(); |
| 536 const bool goog_high_pass_filter = audio_constraints.GetGoogHighpassFilter(); | 573 const bool goog_high_pass_filter = audio_constraints.GetGoogHighpassFilter(); |
| 537 // Return immediately if no goog constraint is enabled. | 574 |
| 575 // Return immediately if none of the goog constraints requiring |
| 576 // webrtc::AudioProcessing are enabled. |
| 538 if (!echo_cancellation && !goog_experimental_aec && !goog_ns && | 577 if (!echo_cancellation && !goog_experimental_aec && !goog_ns && |
| 539 !goog_high_pass_filter && !goog_typing_detection && | 578 !goog_high_pass_filter && !goog_typing_detection && |
| 540 !goog_agc && !goog_experimental_ns && !goog_beamforming) { | 579 !goog_agc && !goog_experimental_ns && !goog_beamforming) { |
| 580 // Sanity-check: WouldModifyAudio() should return true iff |
| 581 // |audio_mirroring_| is true. |
| 582 DCHECK_EQ(audio_mirroring_, WouldModifyAudio(constraints, |
| 583 input_params.effects)); |
| 541 RecordProcessingState(AUDIO_PROCESSING_DISABLED); | 584 RecordProcessingState(AUDIO_PROCESSING_DISABLED); |
| 542 return; | 585 return; |
| 543 } | 586 } |
| 544 | 587 |
| 588 // Sanity-check: WouldModifyAudio() should return true because the above logic |
| 589 // has determined webrtc::AudioProcessing will be used. |
| 590 DCHECK(WouldModifyAudio(constraints, input_params.effects)); |
| 591 |
| 545 // Experimental options provided at creation. | 592 // Experimental options provided at creation. |
| 546 webrtc::Config config; | 593 webrtc::Config config; |
| 547 config.Set<webrtc::ExtendedFilter>( | 594 config.Set<webrtc::ExtendedFilter>( |
| 548 new webrtc::ExtendedFilter(goog_experimental_aec)); | 595 new webrtc::ExtendedFilter(goog_experimental_aec)); |
| 549 config.Set<webrtc::ExperimentalNs>( | 596 config.Set<webrtc::ExperimentalNs>( |
| 550 new webrtc::ExperimentalNs(goog_experimental_ns)); | 597 new webrtc::ExperimentalNs(goog_experimental_ns)); |
| 551 config.Set<webrtc::DelayAgnostic>(new webrtc::DelayAgnostic(true)); | 598 config.Set<webrtc::DelayAgnostic>(new webrtc::DelayAgnostic(true)); |
| 552 if (UseAecRefinedAdaptiveFilter()) { | 599 if (UseAecRefinedAdaptiveFilter()) { |
| 553 config.Set<webrtc::RefinedAdaptiveFilter>( | 600 config.Set<webrtc::RefinedAdaptiveFilter>( |
| 554 new webrtc::RefinedAdaptiveFilter(true)); | 601 new webrtc::RefinedAdaptiveFilter(true)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 0 : agc->stream_analog_level(); | 817 0 : agc->stream_analog_level(); |
| 771 } | 818 } |
| 772 | 819 |
| 773 void MediaStreamAudioProcessor::UpdateAecStats() { | 820 void MediaStreamAudioProcessor::UpdateAecStats() { |
| 774 DCHECK(main_thread_checker_.CalledOnValidThread()); | 821 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 775 if (echo_information_) | 822 if (echo_information_) |
| 776 echo_information_->UpdateAecStats(audio_processing_->echo_cancellation()); | 823 echo_information_->UpdateAecStats(audio_processing_->echo_cancellation()); |
| 777 } | 824 } |
| 778 | 825 |
| 779 } // namespace content | 826 } // namespace content |
| OLD | NEW |