| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webrtc/processed_local_audio_source.h" | 5 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "content/renderer/media/audio_device_factory.h" | 10 #include "content/renderer/media/audio_device_factory.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Sanity-check that the constraints, plus the additional input effects are | 98 // Sanity-check that the constraints, plus the additional input effects are |
| 99 // valid when combined. | 99 // valid when combined. |
| 100 const MediaAudioConstraints audio_constraints( | 100 const MediaAudioConstraints audio_constraints( |
| 101 constraints_, device_info().device.input.effects); | 101 constraints_, device_info().device.input.effects); |
| 102 if (!audio_constraints.IsValid()) { | 102 if (!audio_constraints.IsValid()) { |
| 103 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " | 103 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " |
| 104 " because MediaAudioConstraints are not valid."); | 104 " because MediaAudioConstraints are not valid."); |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Build an AudioOptions by applying relevant constraints to it, and then use | |
| 109 // it to create a webrtc::AudioSourceInterface instance. | |
| 110 cricket::AudioOptions rtc_options; | |
| 111 rtc_options.echo_cancellation = ConstraintToOptional( | |
| 112 constraints_, &blink::WebMediaTrackConstraintSet::echoCancellation); | |
| 113 rtc_options.delay_agnostic_aec = ConstraintToOptional( | |
| 114 constraints_, &blink::WebMediaTrackConstraintSet::googDAEchoCancellation); | |
| 115 rtc_options.auto_gain_control = ConstraintToOptional( | |
| 116 constraints_, &blink::WebMediaTrackConstraintSet::googAutoGainControl); | |
| 117 rtc_options.experimental_agc = ConstraintToOptional( | |
| 118 constraints_, | |
| 119 &blink::WebMediaTrackConstraintSet::googExperimentalAutoGainControl); | |
| 120 rtc_options.noise_suppression = ConstraintToOptional( | |
| 121 constraints_, &blink::WebMediaTrackConstraintSet::googNoiseSuppression); | |
| 122 rtc_options.experimental_ns = ConstraintToOptional( | |
| 123 constraints_, | |
| 124 &blink::WebMediaTrackConstraintSet::googExperimentalNoiseSuppression); | |
| 125 rtc_options.highpass_filter = ConstraintToOptional( | |
| 126 constraints_, &blink::WebMediaTrackConstraintSet::googHighpassFilter); | |
| 127 rtc_options.typing_detection = ConstraintToOptional( | |
| 128 constraints_, | |
| 129 &blink::WebMediaTrackConstraintSet::googTypingNoiseDetection); | |
| 130 rtc_options.stereo_swapping = ConstraintToOptional( | |
| 131 constraints_, &blink::WebMediaTrackConstraintSet::googAudioMirroring); | |
| 132 MediaAudioConstraints::ApplyFixedAudioConstraints(&rtc_options); | |
| 133 if (device_info().device.input.effects & | 108 if (device_info().device.input.effects & |
| 134 media::AudioParameters::ECHO_CANCELLER) { | 109 media::AudioParameters::ECHO_CANCELLER) { |
| 135 // TODO(hta): Figure out if we should be looking at echoCancellation. | 110 // TODO(hta): Figure out if we should be looking at echoCancellation. |
| 136 // Previous code had googEchoCancellation only. | 111 // Previous code had googEchoCancellation only. |
| 137 const blink::BooleanConstraint& echoCancellation = | 112 const blink::BooleanConstraint& echoCancellation = |
| 138 constraints_.basic().googEchoCancellation; | 113 constraints_.basic().googEchoCancellation; |
| 139 if (echoCancellation.hasExact() && !echoCancellation.exact()) { | 114 if (echoCancellation.hasExact() && !echoCancellation.exact()) { |
| 140 StreamDeviceInfo modified_device_info(device_info()); | 115 StreamDeviceInfo modified_device_info(device_info()); |
| 141 modified_device_info.device.input.effects &= | 116 modified_device_info.device.input.effects &= |
| 142 ~media::AudioParameters::ECHO_CANCELLER; | 117 ~media::AudioParameters::ECHO_CANCELLER; |
| 143 SetDeviceInfo(modified_device_info); | 118 SetDeviceInfo(modified_device_info); |
| 144 } | 119 } |
| 145 rtc_options.echo_cancellation = rtc::Optional<bool>(false); | |
| 146 } | |
| 147 rtc_source_ = pc_factory_->CreateLocalAudioSource(rtc_options); | |
| 148 if (rtc_source_->state() != webrtc::MediaSourceInterface::kLive) { | |
| 149 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " | |
| 150 " because the rtc LocalAudioSource is not live."); | |
| 151 return false; | |
| 152 } | 120 } |
| 153 | 121 |
| 154 // Create the MediaStreamAudioProcessor, bound to the WebRTC audio device | 122 // Create the MediaStreamAudioProcessor, bound to the WebRTC audio device |
| 155 // module. | 123 // module. |
| 156 WebRtcAudioDeviceImpl* const rtc_audio_device = | 124 WebRtcAudioDeviceImpl* const rtc_audio_device = |
| 157 pc_factory_->GetWebRtcAudioDevice(); | 125 pc_factory_->GetWebRtcAudioDevice(); |
| 158 if (!rtc_audio_device) { | 126 if (!rtc_audio_device) { |
| 159 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " | 127 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " |
| 160 " because there is no WebRtcAudioDeviceImpl instance."); | 128 " because there is no WebRtcAudioDeviceImpl instance."); |
| 161 return false; | 129 return false; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 365 |
| 398 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a | 366 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a |
| 399 // fall-back. | 367 // fall-back. |
| 400 // | 368 // |
| 401 // TODO(miu): Identify where/why the buffer size might be missing, fix the | 369 // TODO(miu): Identify where/why the buffer size might be missing, fix the |
| 402 // code, and then require it here. | 370 // code, and then require it here. |
| 403 return (sample_rate / 100); | 371 return (sample_rate / 100); |
| 404 } | 372 } |
| 405 | 373 |
| 406 } // namespace content | 374 } // namespace content |
| OLD | NEW |