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" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 #else | 245 #else |
246 const bool enable_experimental_aec = GetPropertyFromConstraints( | 246 const bool enable_experimental_aec = GetPropertyFromConstraints( |
247 &native_constraints, | 247 &native_constraints, |
248 MediaConstraintsInterface::kExperimentalEchoCancellation); | 248 MediaConstraintsInterface::kExperimentalEchoCancellation); |
249 const bool enable_typing_detection = GetPropertyFromConstraints( | 249 const bool enable_typing_detection = GetPropertyFromConstraints( |
250 &native_constraints, MediaConstraintsInterface::kTypingNoiseDetection); | 250 &native_constraints, MediaConstraintsInterface::kTypingNoiseDetection); |
251 #endif | 251 #endif |
252 | 252 |
253 const bool enable_ns = GetPropertyFromConstraints( | 253 const bool enable_ns = GetPropertyFromConstraints( |
254 &native_constraints, MediaConstraintsInterface::kNoiseSuppression); | 254 &native_constraints, MediaConstraintsInterface::kNoiseSuppression); |
| 255 const bool enable_experimental_ns = GetPropertyFromConstraints( |
| 256 &native_constraints, |
| 257 MediaConstraintsInterface::kExperimentalNoiseSuppression); |
255 const bool enable_high_pass_filter = GetPropertyFromConstraints( | 258 const bool enable_high_pass_filter = GetPropertyFromConstraints( |
256 &native_constraints, MediaConstraintsInterface::kHighpassFilter); | 259 &native_constraints, MediaConstraintsInterface::kHighpassFilter); |
257 | 260 |
258 audio_mirroring_ = GetPropertyFromConstraints( | 261 audio_mirroring_ = GetPropertyFromConstraints( |
259 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); | 262 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); |
260 | 263 |
261 // Return immediately if no audio processing component is enabled. | 264 // Return immediately if no audio processing component is enabled. |
262 if (!enable_aec && !enable_experimental_aec && !enable_ns && | 265 if (!enable_aec && !enable_experimental_aec && !enable_ns && |
263 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && | 266 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && |
264 !audio_mirroring_) { | 267 !audio_mirroring_ && !enable_experimental_ns) { |
265 return; | 268 return; |
266 } | 269 } |
267 | 270 |
268 // Create and configure the webrtc::AudioProcessing. | 271 // Create and configure the webrtc::AudioProcessing. |
269 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); | 272 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); |
270 | 273 |
271 // Enable the audio processing components. | 274 // Enable the audio processing components. |
272 if (enable_aec) { | 275 if (enable_aec) { |
273 EnableEchoCancellation(audio_processing_.get()); | 276 EnableEchoCancellation(audio_processing_.get()); |
274 if (enable_experimental_aec) | 277 if (enable_experimental_aec) |
275 EnableExperimentalEchoCancellation(audio_processing_.get()); | 278 EnableExperimentalEchoCancellation(audio_processing_.get()); |
276 | 279 |
277 if (playout_data_source_) | 280 if (playout_data_source_) |
278 playout_data_source_->AddPlayoutSink(this); | 281 playout_data_source_->AddPlayoutSink(this); |
279 } | 282 } |
280 | 283 |
281 if (enable_ns) | 284 if (enable_ns) |
282 EnableNoiseSuppression(audio_processing_.get()); | 285 EnableNoiseSuppression(audio_processing_.get()); |
283 | 286 |
| 287 if (enable_experimental_ns) |
| 288 EnableExperimentalNoiseSuppression(audio_processing_.get()); |
| 289 |
284 if (enable_high_pass_filter) | 290 if (enable_high_pass_filter) |
285 EnableHighPassFilter(audio_processing_.get()); | 291 EnableHighPassFilter(audio_processing_.get()); |
286 | 292 |
287 if (enable_typing_detection) { | 293 if (enable_typing_detection) { |
288 // TODO(xians): Remove this |typing_detector_| after the typing suppression | 294 // TODO(xians): Remove this |typing_detector_| after the typing suppression |
289 // is enabled by default. | 295 // is enabled by default. |
290 typing_detector_.reset(new webrtc::TypingDetection()); | 296 typing_detector_.reset(new webrtc::TypingDetection()); |
291 EnableTypingDetection(audio_processing_.get(), typing_detector_.get()); | 297 EnableTypingDetection(audio_processing_.get(), typing_detector_.get()); |
292 } | 298 } |
293 | 299 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 int64 capture_delay_ms = capture_delay.InMilliseconds(); | 389 int64 capture_delay_ms = capture_delay.InMilliseconds(); |
384 DCHECK_LT(capture_delay_ms, | 390 DCHECK_LT(capture_delay_ms, |
385 std::numeric_limits<base::subtle::Atomic32>::max()); | 391 std::numeric_limits<base::subtle::Atomic32>::max()); |
386 int total_delay_ms = capture_delay_ms + render_delay_ms; | 392 int total_delay_ms = capture_delay_ms + render_delay_ms; |
387 if (total_delay_ms > 300) { | 393 if (total_delay_ms > 300) { |
388 LOG(WARNING) << "Large audio delay, capture delay: " << capture_delay_ms | 394 LOG(WARNING) << "Large audio delay, capture delay: " << capture_delay_ms |
389 << "ms; render delay: " << render_delay_ms << "ms"; | 395 << "ms; render delay: " << render_delay_ms << "ms"; |
390 } | 396 } |
391 | 397 |
392 audio_processing_->set_stream_delay_ms(total_delay_ms); | 398 audio_processing_->set_stream_delay_ms(total_delay_ms); |
| 399 |
393 webrtc::GainControl* agc = audio_processing_->gain_control(); | 400 webrtc::GainControl* agc = audio_processing_->gain_control(); |
394 int err = agc->set_stream_analog_level(volume); | 401 int err = agc->set_stream_analog_level(volume); |
395 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err; | 402 DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err; |
| 403 |
| 404 audio_processing_->set_stream_key_pressed(key_pressed); |
| 405 |
396 err = audio_processing_->ProcessStream(audio_frame); | 406 err = audio_processing_->ProcessStream(audio_frame); |
397 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; | 407 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; |
398 | 408 |
399 // TODO(xians): Add support for typing detection, audio level calculation. | 409 // TODO(xians): Add support for typing detection, audio level calculation. |
400 | 410 |
401 if (audio_mirroring_ && audio_frame->num_channels_ == 2) { | 411 if (audio_mirroring_ && audio_frame->num_channels_ == 2) { |
402 // TODO(xians): Swap the stereo channels after switching to media::AudioBus. | 412 // TODO(xians): Swap the stereo channels after switching to media::AudioBus. |
403 } | 413 } |
404 | 414 |
405 if (typing_detector_ && | 415 if (typing_detector_ && |
(...skipping 14 matching lines...) Expand all Loading... |
420 if (!audio_processing_.get()) | 430 if (!audio_processing_.get()) |
421 return; | 431 return; |
422 | 432 |
423 if (playout_data_source_) | 433 if (playout_data_source_) |
424 playout_data_source_->RemovePlayoutSink(this); | 434 playout_data_source_->RemovePlayoutSink(this); |
425 | 435 |
426 audio_processing_.reset(); | 436 audio_processing_.reset(); |
427 } | 437 } |
428 | 438 |
429 } // namespace content | 439 } // namespace content |
OLD | NEW |