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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "content/renderer/media/media_stream_audio_processor_options.h" | 10 #include "content/renderer/media/media_stream_audio_processor_options.h" |
11 #include "content/renderer/media/rtc_media_constraints.h" | 11 #include "content/renderer/media/rtc_media_constraints.h" |
12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
13 #include "media/base/audio_converter.h" | 13 #include "media/base/audio_converter.h" |
14 #include "media/base/audio_fifo.h" | 14 #include "media/base/audio_fifo.h" |
15 #include "media/base/channel_layout.h" | 15 #include "media/base/channel_layout.h" |
16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
17 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 17 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
| 18 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 using webrtc::AudioProcessing; | 24 using webrtc::AudioProcessing; |
24 using webrtc::MediaConstraintsInterface; | 25 using webrtc::MediaConstraintsInterface; |
25 | 26 |
26 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
27 const int kAudioProcessingSampleRate = 16000; | 28 const int kAudioProcessingSampleRate = 16000; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 media::AudioConverter audio_converter_; | 137 media::AudioConverter audio_converter_; |
137 scoped_ptr<media::AudioBus> audio_wrapper_; | 138 scoped_ptr<media::AudioBus> audio_wrapper_; |
138 scoped_ptr<media::AudioFifo> fifo_; | 139 scoped_ptr<media::AudioFifo> fifo_; |
139 }; | 140 }; |
140 | 141 |
141 MediaStreamAudioProcessor::MediaStreamAudioProcessor( | 142 MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
142 const media::AudioParameters& source_params, | 143 const media::AudioParameters& source_params, |
143 const blink::WebMediaConstraints& constraints, | 144 const blink::WebMediaConstraints& constraints, |
144 int effects) | 145 int effects) |
145 : render_delay_ms_(0), | 146 : render_delay_ms_(0), |
146 audio_mirroring_(false) { | 147 audio_mirroring_(false), |
| 148 typing_detected_(false) { |
147 capture_thread_checker_.DetachFromThread(); | 149 capture_thread_checker_.DetachFromThread(); |
148 render_thread_checker_.DetachFromThread(); | 150 render_thread_checker_.DetachFromThread(); |
149 InitializeAudioProcessingModule(constraints, effects); | 151 InitializeAudioProcessingModule(constraints, effects); |
150 InitializeCaptureConverter(source_params); | 152 InitializeCaptureConverter(source_params); |
151 } | 153 } |
152 | 154 |
153 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 155 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
154 DCHECK(main_thread_checker_.CalledOnValidThread()); | 156 DCHECK(main_thread_checker_.CalledOnValidThread()); |
155 StopAudioProcessing(); | 157 StopAudioProcessing(); |
156 } | 158 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 const bool enable_ns = GetPropertyFromConstraints( | 259 const bool enable_ns = GetPropertyFromConstraints( |
258 &native_constraints, MediaConstraintsInterface::kNoiseSuppression); | 260 &native_constraints, MediaConstraintsInterface::kNoiseSuppression); |
259 const bool enable_high_pass_filter = GetPropertyFromConstraints( | 261 const bool enable_high_pass_filter = GetPropertyFromConstraints( |
260 &native_constraints, MediaConstraintsInterface::kHighpassFilter); | 262 &native_constraints, MediaConstraintsInterface::kHighpassFilter); |
261 | 263 |
262 audio_mirroring_ = GetPropertyFromConstraints( | 264 audio_mirroring_ = GetPropertyFromConstraints( |
263 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); | 265 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); |
264 | 266 |
265 // Return immediately if no audio processing component is enabled. | 267 // Return immediately if no audio processing component is enabled. |
266 if (!enable_aec && !enable_experimental_aec && !enable_ns && | 268 if (!enable_aec && !enable_experimental_aec && !enable_ns && |
267 !enable_high_pass_filter && !enable_typing_detection && !enable_agc) { | 269 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && |
| 270 !audio_mirroring_) { |
268 return; | 271 return; |
269 } | 272 } |
270 | 273 |
271 // Create and configure the webrtc::AudioProcessing. | 274 // Create and configure the webrtc::AudioProcessing. |
272 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); | 275 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); |
273 | 276 |
274 // Enable the audio processing components. | 277 // Enable the audio processing components. |
275 if (enable_aec) { | 278 if (enable_aec) { |
276 EnableEchoCancellation(audio_processing_.get()); | 279 EnableEchoCancellation(audio_processing_.get()); |
277 if (enable_experimental_aec) | 280 if (enable_experimental_aec) |
278 EnableExperimentalEchoCancellation(audio_processing_.get()); | 281 EnableExperimentalEchoCancellation(audio_processing_.get()); |
279 } | 282 } |
280 | 283 |
281 if (enable_ns) | 284 if (enable_ns) |
282 EnableNoiseSuppression(audio_processing_.get()); | 285 EnableNoiseSuppression(audio_processing_.get()); |
283 | 286 |
284 if (enable_high_pass_filter) | 287 if (enable_high_pass_filter) |
285 EnableHighPassFilter(audio_processing_.get()); | 288 EnableHighPassFilter(audio_processing_.get()); |
286 | 289 |
287 if (enable_typing_detection) | 290 if (enable_typing_detection) { |
288 EnableTypingDetection(audio_processing_.get()); | 291 // TODO(xians): Remove this |typing_detector_| after the typing suppression |
| 292 // is enabled by default. |
| 293 typing_detector_.reset(new webrtc::TypingDetection()); |
| 294 EnableTypingDetection(audio_processing_.get(), typing_detector_.get()); |
| 295 } |
289 | 296 |
290 if (enable_agc) | 297 if (enable_agc) |
291 EnableAutomaticGainControl(audio_processing_.get()); | 298 EnableAutomaticGainControl(audio_processing_.get()); |
292 | 299 |
293 // Configure the audio format the audio processing is running on. This | 300 // Configure the audio format the audio processing is running on. This |
294 // has to be done after all the needed components are enabled. | 301 // has to be done after all the needed components are enabled. |
295 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), | 302 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), |
296 0); | 303 0); |
297 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, | 304 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, |
298 kAudioProcessingNumberOfChannel), | 305 kAudioProcessingNumberOfChannel), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err; | 398 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err; |
392 err = audio_processing_->ProcessStream(audio_frame); | 399 err = audio_processing_->ProcessStream(audio_frame); |
393 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; | 400 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; |
394 | 401 |
395 // TODO(xians): Add support for typing detection, audio level calculation. | 402 // TODO(xians): Add support for typing detection, audio level calculation. |
396 | 403 |
397 if (audio_mirroring_ && audio_frame->num_channels_ == 2) { | 404 if (audio_mirroring_ && audio_frame->num_channels_ == 2) { |
398 // TODO(xians): Swap the stereo channels after switching to media::AudioBus. | 405 // TODO(xians): Swap the stereo channels after switching to media::AudioBus. |
399 } | 406 } |
400 | 407 |
| 408 if (typing_detector_ && |
| 409 audio_frame->vad_activity_ != webrtc::AudioFrame::kVadUnknown) { |
| 410 bool vad_active = |
| 411 (audio_frame->vad_activity_ == webrtc::AudioFrame::kVadActive); |
| 412 // TODO(xians): Pass this |typing_detected_| to peer connection. |
| 413 typing_detected_ = typing_detector_->Process(key_pressed, vad_active); |
| 414 } |
| 415 |
401 // Return 0 if the volume has not been changed, otherwise return the new | 416 // Return 0 if the volume has not been changed, otherwise return the new |
402 // volume. | 417 // volume. |
403 return (agc->stream_analog_level() == volume) ? | 418 return (agc->stream_analog_level() == volume) ? |
404 0 : agc->stream_analog_level(); | 419 0 : agc->stream_analog_level(); |
405 } | 420 } |
406 | 421 |
407 void MediaStreamAudioProcessor::StopAudioProcessing() { | 422 void MediaStreamAudioProcessor::StopAudioProcessing() { |
408 if (!audio_processing_.get()) | 423 if (!audio_processing_.get()) |
409 return; | 424 return; |
410 | 425 |
411 audio_processing_.reset(); | 426 audio_processing_.reset(); |
412 } | 427 } |
413 | 428 |
414 } // namespace content | 429 } // namespace content |
OLD | NEW |