Chromium Code Reviews| 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 "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | |
| 10 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 11 #include "content/renderer/media/media_stream_audio_processor_options.h" | 12 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 12 #include "content/renderer/media/rtc_media_constraints.h" | 13 #include "content/renderer/media/rtc_media_constraints.h" |
| 13 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/audio_converter.h" | 15 #include "media/base/audio_converter.h" |
| 15 #include "media/base/audio_fifo.h" | 16 #include "media/base/audio_fifo.h" |
| 16 #include "media/base/channel_layout.h" | 17 #include "media/base/channel_layout.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 18 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 18 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" | 19 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" |
| 19 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" | 20 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 using webrtc::AudioProcessing; | 26 using webrtc::AudioProcessing; |
| 26 using webrtc::MediaConstraintsInterface; | 27 using webrtc::MediaConstraintsInterface; |
| 27 | 28 |
| 28 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 29 const int kAudioProcessingSampleRate = 16000; | 30 const int kAudioProcessingSampleRate = 16000; |
| 30 #else | 31 #else |
| 31 const int kAudioProcessingSampleRate = 32000; | 32 const int kAudioProcessingSampleRate = 32000; |
| 32 #endif | 33 #endif |
| 33 const int kAudioProcessingNumberOfChannel = 1; | 34 const int kAudioProcessingNumberOfChannel = 1; |
| 34 | 35 |
| 35 const int kMaxNumberOfBuffersInFifo = 2; | 36 const int kMaxNumberOfBuffersInFifo = 2; |
| 36 | 37 |
| 38 enum AudioTrackProcessingStates { | |
| 39 AUDIO_PROCESSING_ENABLED = 0, | |
| 40 AUDIO_PROCESSING_DISABLED, | |
| 41 AUDIO_PROCESSING_MAX | |
| 42 }; | |
| 43 | |
| 37 } // namespace | 44 } // namespace |
| 38 | 45 |
| 39 class MediaStreamAudioProcessor::MediaStreamAudioConverter | 46 class MediaStreamAudioProcessor::MediaStreamAudioConverter |
| 40 : public media::AudioConverter::InputCallback { | 47 : public media::AudioConverter::InputCallback { |
| 41 public: | 48 public: |
| 42 MediaStreamAudioConverter(const media::AudioParameters& source_params, | 49 MediaStreamAudioConverter(const media::AudioParameters& source_params, |
| 43 const media::AudioParameters& sink_params) | 50 const media::AudioParameters& sink_params) |
| 44 : source_params_(source_params), | 51 : source_params_(source_params), |
| 45 sink_params_(sink_params), | 52 sink_params_(sink_params), |
| 46 audio_converter_(source_params, sink_params_, false) { | 53 audio_converter_(source_params, sink_params_, false) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { | 265 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { |
| 259 stats->typing_noise_detected = | 266 stats->typing_noise_detected = |
| 260 (base::subtle::Acquire_Load(&typing_detected_) != false); | 267 (base::subtle::Acquire_Load(&typing_detected_) != false); |
| 261 GetAecStats(audio_processing_.get(), stats); | 268 GetAecStats(audio_processing_.get(), stats); |
| 262 } | 269 } |
| 263 | 270 |
| 264 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( | 271 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
| 265 const blink::WebMediaConstraints& constraints, int effects, | 272 const blink::WebMediaConstraints& constraints, int effects, |
| 266 MediaStreamType type) { | 273 MediaStreamType type) { |
| 267 DCHECK(!audio_processing_); | 274 DCHECK(!audio_processing_); |
| 268 if (!IsAudioTrackProcessingEnabled()) | 275 if (!IsAudioTrackProcessingEnabled()) { |
| 276 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates", | |
| 277 AUDIO_PROCESSING_DISABLED, AUDIO_PROCESSING_MAX); | |
| 269 return; | 278 return; |
| 279 } | |
| 270 | 280 |
| 271 RTCMediaConstraints native_constraints(constraints); | 281 RTCMediaConstraints native_constraints(constraints); |
| 272 | 282 |
| 273 // Only apply the fixed constraints for gUM of MEDIA_DEVICE_AUDIO_CAPTURE. | 283 // Only apply the fixed constraints for gUM of MEDIA_DEVICE_AUDIO_CAPTURE. |
| 274 DCHECK(IsAudioMediaType(type)); | 284 DCHECK(IsAudioMediaType(type)); |
| 275 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) | 285 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) |
| 276 ApplyFixedAudioConstraints(&native_constraints); | 286 ApplyFixedAudioConstraints(&native_constraints); |
| 277 | 287 |
| 278 if (effects & media::AudioParameters::ECHO_CANCELLER) { | 288 if (effects & media::AudioParameters::ECHO_CANCELLER) { |
| 279 // If platform echo canceller is enabled, disable the software AEC. | 289 // If platform echo canceller is enabled, disable the software AEC. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 const bool enable_high_pass_filter = GetPropertyFromConstraints( | 322 const bool enable_high_pass_filter = GetPropertyFromConstraints( |
| 313 &native_constraints, MediaConstraintsInterface::kHighpassFilter); | 323 &native_constraints, MediaConstraintsInterface::kHighpassFilter); |
| 314 | 324 |
| 315 audio_mirroring_ = GetPropertyFromConstraints( | 325 audio_mirroring_ = GetPropertyFromConstraints( |
| 316 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); | 326 &native_constraints, webrtc::MediaConstraintsInterface::kAudioMirroring); |
| 317 | 327 |
| 318 // Return immediately if no audio processing component is enabled. | 328 // Return immediately if no audio processing component is enabled. |
| 319 if (!enable_aec && !enable_experimental_aec && !enable_ns && | 329 if (!enable_aec && !enable_experimental_aec && !enable_ns && |
| 320 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && | 330 !enable_high_pass_filter && !enable_typing_detection && !enable_agc && |
| 321 !enable_experimental_ns) { | 331 !enable_experimental_ns) { |
| 332 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates", | |
| 333 AUDIO_PROCESSING_DISABLED, AUDIO_PROCESSING_MAX); | |
|
tommi (sloooow) - chröme
2014/03/14 14:38:32
Could we have a different value for this case?
He
no longer working on chromium
2014/03/14 14:43:56
Do we really want this? AUDIO_PROCESSING_BYPASSED
| |
| 322 return; | 334 return; |
| 323 } | 335 } |
| 324 | 336 |
| 325 // Create and configure the webrtc::AudioProcessing. | 337 // Create and configure the webrtc::AudioProcessing. |
| 326 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); | 338 audio_processing_.reset(webrtc::AudioProcessing::Create(0)); |
| 327 | 339 |
| 328 // Enable the audio processing components. | 340 // Enable the audio processing components. |
| 329 if (enable_aec) { | 341 if (enable_aec) { |
| 330 EnableEchoCancellation(audio_processing_.get()); | 342 EnableEchoCancellation(audio_processing_.get()); |
| 331 if (enable_experimental_aec) | 343 if (enable_experimental_aec) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 354 if (enable_agc) | 366 if (enable_agc) |
| 355 EnableAutomaticGainControl(audio_processing_.get()); | 367 EnableAutomaticGainControl(audio_processing_.get()); |
| 356 | 368 |
| 357 // Configure the audio format the audio processing is running on. This | 369 // Configure the audio format the audio processing is running on. This |
| 358 // has to be done after all the needed components are enabled. | 370 // has to be done after all the needed components are enabled. |
| 359 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), | 371 CHECK_EQ(audio_processing_->set_sample_rate_hz(kAudioProcessingSampleRate), |
| 360 0); | 372 0); |
| 361 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, | 373 CHECK_EQ(audio_processing_->set_num_channels(kAudioProcessingNumberOfChannel, |
| 362 kAudioProcessingNumberOfChannel), | 374 kAudioProcessingNumberOfChannel), |
| 363 0); | 375 0); |
| 376 | |
| 377 UMA_HISTOGRAM_ENUMERATION("Media.AudioTrackProcessingStates", | |
| 378 AUDIO_PROCESSING_ENABLED, AUDIO_PROCESSING_MAX); | |
| 364 } | 379 } |
| 365 | 380 |
| 366 void MediaStreamAudioProcessor::InitializeCaptureConverter( | 381 void MediaStreamAudioProcessor::InitializeCaptureConverter( |
| 367 const media::AudioParameters& source_params) { | 382 const media::AudioParameters& source_params) { |
| 368 DCHECK(main_thread_checker_.CalledOnValidThread()); | 383 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 369 DCHECK(source_params.IsValid()); | 384 DCHECK(source_params.IsValid()); |
| 370 | 385 |
| 371 // Create and initialize audio converter for the source data. | 386 // Create and initialize audio converter for the source data. |
| 372 // When the webrtc AudioProcessing is enabled, the sink format of the | 387 // When the webrtc AudioProcessing is enabled, the sink format of the |
| 373 // converter will be the same as the post-processed data format, which is | 388 // converter will be the same as the post-processed data format, which is |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 } | 503 } |
| 489 | 504 |
| 490 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() const { | 505 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() const { |
| 491 const std::string group_name = | 506 const std::string group_name = |
| 492 base::FieldTrialList::FindFullName("MediaStreamAudioTrackProcessing"); | 507 base::FieldTrialList::FindFullName("MediaStreamAudioTrackProcessing"); |
| 493 return group_name == "Enabled" || CommandLine::ForCurrentProcess()->HasSwitch( | 508 return group_name == "Enabled" || CommandLine::ForCurrentProcess()->HasSwitch( |
| 494 switches::kEnableAudioTrackProcessing); | 509 switches::kEnableAudioTrackProcessing); |
| 495 } | 510 } |
| 496 | 511 |
| 497 } // namespace content | 512 } // namespace content |
| OLD | NEW |