diff options
author | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 18:48:57 +0000 |
---|---|---|
committer | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-20 18:48:57 +0000 |
commit | a5317ac1a3c8cc7752f88db64727ef05ff2d264d (patch) | |
tree | b269d6c9b9b0c18754d7bcd053da71d6cdb50d06 | |
parent | 0e14a1804e7a94f445553b8c860678c0b56f97bb (diff) | |
download | chromium_src-a5317ac1a3c8cc7752f88db64727ef05ff2d264d.zip chromium_src-a5317ac1a3c8cc7752f88db64727ef05ff2d264d.tar.gz chromium_src-a5317ac1a3c8cc7752f88db64727ef05ff2d264d.tar.bz2 |
Adding typing detection to the APM in chrome.
BUG=264611
Review URL: https://codereview.chromium.org/169803003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252334 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 35 insertions, 6 deletions
diff --git a/content/renderer/media/media_stream_audio_processor.cc b/content/renderer/media/media_stream_audio_processor.cc index 4422b50..58e11dd 100644 --- a/content/renderer/media/media_stream_audio_processor.cc +++ b/content/renderer/media/media_stream_audio_processor.cc @@ -15,6 +15,7 @@ #include "media/base/channel_layout.h" #include "third_party/WebKit/public/platform/WebMediaConstraints.h" #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" +#include "third_party/webrtc/modules/audio_processing/typing_detection.h" namespace content { @@ -143,7 +144,8 @@ MediaStreamAudioProcessor::MediaStreamAudioProcessor( const blink::WebMediaConstraints& constraints, int effects) : render_delay_ms_(0), - audio_mirroring_(false) { + audio_mirroring_(false), + typing_detected_(false) { capture_thread_checker_.DetachFromThread(); render_thread_checker_.DetachFromThread(); InitializeAudioProcessingModule(constraints, effects); @@ -264,7 +266,8 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( // Return immediately if no audio processing component is enabled. if (!enable_aec && !enable_experimental_aec && !enable_ns && - !enable_high_pass_filter && !enable_typing_detection && !enable_agc) { + !enable_high_pass_filter && !enable_typing_detection && !enable_agc && + !audio_mirroring_) { return; } @@ -284,8 +287,12 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( if (enable_high_pass_filter) EnableHighPassFilter(audio_processing_.get()); - if (enable_typing_detection) - EnableTypingDetection(audio_processing_.get()); + if (enable_typing_detection) { + // TODO(xians): Remove this |typing_detector_| after the typing suppression + // is enabled by default. + typing_detector_.reset(new webrtc::TypingDetection()); + EnableTypingDetection(audio_processing_.get(), typing_detector_.get()); + } if (enable_agc) EnableAutomaticGainControl(audio_processing_.get()); @@ -398,6 +405,14 @@ int MediaStreamAudioProcessor::ProcessData(webrtc::AudioFrame* audio_frame, // TODO(xians): Swap the stereo channels after switching to media::AudioBus. } + if (typing_detector_ && + audio_frame->vad_activity_ != webrtc::AudioFrame::kVadUnknown) { + bool vad_active = + (audio_frame->vad_activity_ == webrtc::AudioFrame::kVadActive); + // TODO(xians): Pass this |typing_detected_| to peer connection. + typing_detected_ = typing_detector_->Process(key_pressed, vad_active); + } + // Return 0 if the volume has not been changed, otherwise return the new // volume. return (agc->stream_analog_level() == volume) ? diff --git a/content/renderer/media/media_stream_audio_processor.h b/content/renderer/media/media_stream_audio_processor.h index 12c0fc5..1550fe7 100644 --- a/content/renderer/media/media_stream_audio_processor.h +++ b/content/renderer/media/media_stream_audio_processor.h @@ -26,6 +26,7 @@ class AudioParameters; namespace webrtc { class AudioFrame; +class TypingDetection; } namespace content { @@ -154,6 +155,12 @@ class CONTENT_EXPORT MediaStreamAudioProcessor : // Flag to enable the stereo channels mirroring. bool audio_mirroring_; + + // Used by the typing detection. + scoped_ptr<webrtc::TypingDetection> typing_detector_; + + // Result from the typing detection. + bool typing_detected_; }; } // namespace content diff --git a/content/renderer/media/media_stream_audio_processor_options.cc b/content/renderer/media/media_stream_audio_processor_options.cc index 1444ea7..c447404 100644 --- a/content/renderer/media/media_stream_audio_processor_options.cc +++ b/content/renderer/media/media_stream_audio_processor_options.cc @@ -14,6 +14,7 @@ #include "third_party/WebKit/public/platform/WebMediaConstraints.h" #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h" +#include "third_party/webrtc/modules/audio_processing/typing_detection.h" namespace content { @@ -122,11 +123,15 @@ void EnableHighPassFilter(AudioProcessing* audio_processing) { CHECK_EQ(audio_processing->high_pass_filter()->Enable(true), 0); } -void EnableTypingDetection(AudioProcessing* audio_processing) { +void EnableTypingDetection(AudioProcessing* audio_processing, + webrtc::TypingDetection* typing_detector) { int err = audio_processing->voice_detection()->Enable(true); err |= audio_processing->voice_detection()->set_likelihood( webrtc::VoiceDetection::kVeryLowLikelihood); CHECK_EQ(err, 0); + + // Configure the update period to 100ms (10 * 10ms) in the typing detector. + typing_detector->SetParameters(0, 0, 0, 0, 0, 10); } void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing) { diff --git a/content/renderer/media/media_stream_audio_processor_options.h b/content/renderer/media/media_stream_audio_processor_options.h index 6057ae1..3977000 100644 --- a/content/renderer/media/media_stream_audio_processor_options.h +++ b/content/renderer/media/media_stream_audio_processor_options.h @@ -16,6 +16,7 @@ namespace webrtc { class AudioFrame; class AudioProcessing; class MediaConstraintsInterface; +class TypingDetection; } @@ -57,7 +58,8 @@ void EnableNoiseSuppression(AudioProcessing* audio_processing); void EnableHighPassFilter(AudioProcessing* audio_processing); // Enables the typing detection in |audio_processing|. -void EnableTypingDetection(AudioProcessing* audio_processing); +void EnableTypingDetection(AudioProcessing* audio_processing, + webrtc::TypingDetection* typing_detector); // Enables the experimental echo cancellation in |audio_processing|. void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing); |