| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // TODO(xians): consider using SincResampler to save some memcpy. | 135 // TODO(xians): consider using SincResampler to save some memcpy. |
| 136 // Handles mixing and resampling between input and output parameters. | 136 // Handles mixing and resampling between input and output parameters. |
| 137 media::AudioConverter audio_converter_; | 137 media::AudioConverter audio_converter_; |
| 138 scoped_ptr<media::AudioBus> audio_wrapper_; | 138 scoped_ptr<media::AudioBus> audio_wrapper_; |
| 139 scoped_ptr<media::AudioFifo> fifo_; | 139 scoped_ptr<media::AudioFifo> fifo_; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 MediaStreamAudioProcessor::MediaStreamAudioProcessor( | 142 MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
| 143 const blink::WebMediaConstraints& constraints, | 143 const blink::WebMediaConstraints& constraints, |
| 144 int effects, | 144 int effects, |
| 145 MediaStreamType type, |
| 145 WebRtcPlayoutDataSource* playout_data_source) | 146 WebRtcPlayoutDataSource* playout_data_source) |
| 146 : render_delay_ms_(0), | 147 : render_delay_ms_(0), |
| 147 playout_data_source_(playout_data_source), | 148 playout_data_source_(playout_data_source), |
| 148 audio_mirroring_(false), | 149 audio_mirroring_(false), |
| 149 typing_detected_(false) { | 150 typing_detected_(false) { |
| 150 capture_thread_checker_.DetachFromThread(); | 151 capture_thread_checker_.DetachFromThread(); |
| 151 render_thread_checker_.DetachFromThread(); | 152 render_thread_checker_.DetachFromThread(); |
| 152 InitializeAudioProcessingModule(constraints, effects); | 153 InitializeAudioProcessingModule(constraints, effects, type); |
| 153 } | 154 } |
| 154 | 155 |
| 155 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 156 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
| 156 DCHECK(main_thread_checker_.CalledOnValidThread()); | 157 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 157 StopAudioProcessing(); | 158 StopAudioProcessing(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void MediaStreamAudioProcessor::OnCaptureFormatChanged( | 161 void MediaStreamAudioProcessor::OnCaptureFormatChanged( |
| 161 const media::AudioParameters& source_params) { | 162 const media::AudioParameters& source_params) { |
| 162 DCHECK(main_thread_checker_.CalledOnValidThread()); | 163 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 render_converter_.reset(); | 254 render_converter_.reset(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { | 257 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { |
| 257 stats->typing_noise_detected = | 258 stats->typing_noise_detected = |
| 258 (base::subtle::Acquire_Load(&typing_detected_) != false); | 259 (base::subtle::Acquire_Load(&typing_detected_) != false); |
| 259 GetAecStats(audio_processing_.get(), stats); | 260 GetAecStats(audio_processing_.get(), stats); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( | 263 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
| 263 const blink::WebMediaConstraints& constraints, int effects) { | 264 const blink::WebMediaConstraints& constraints, int effects, |
| 265 MediaStreamType type) { |
| 264 DCHECK(!audio_processing_); | 266 DCHECK(!audio_processing_); |
| 265 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 267 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 266 switches::kEnableAudioTrackProcessing)) { | 268 switches::kEnableAudioTrackProcessing)) { |
| 267 return; | 269 return; |
| 268 } | 270 } |
| 269 | 271 |
| 270 RTCMediaConstraints native_constraints(constraints); | 272 RTCMediaConstraints native_constraints(constraints); |
| 271 ApplyFixedAudioConstraints(&native_constraints); | 273 |
| 274 // Only apply the fixed constraints for gUM of MEDIA_DEVICE_AUDIO_CAPTURE. |
| 275 DCHECK(IsAudioMediaType(type)); |
| 276 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) |
| 277 ApplyFixedAudioConstraints(&native_constraints); |
| 278 |
| 272 if (effects & media::AudioParameters::ECHO_CANCELLER) { | 279 if (effects & media::AudioParameters::ECHO_CANCELLER) { |
| 273 // If platform echo canceller is enabled, disable the software AEC. | 280 // If platform echo canceller is enabled, disable the software AEC. |
| 274 native_constraints.AddMandatory( | 281 native_constraints.AddMandatory( |
| 275 MediaConstraintsInterface::kEchoCancellation, | 282 MediaConstraintsInterface::kEchoCancellation, |
| 276 MediaConstraintsInterface::kValueFalse, true); | 283 MediaConstraintsInterface::kValueFalse, true); |
| 277 } | 284 } |
| 278 | 285 |
| 279 #if defined(OS_IOS) | 286 #if defined(OS_IOS) |
| 280 // On iOS, VPIO provides built-in AEC and AGC. | 287 // On iOS, VPIO provides built-in AEC and AGC. |
| 281 const bool enable_aec = false; | 288 const bool enable_aec = false; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 482 |
| 476 StopAecDump(); | 483 StopAecDump(); |
| 477 | 484 |
| 478 if (playout_data_source_) | 485 if (playout_data_source_) |
| 479 playout_data_source_->RemovePlayoutSink(this); | 486 playout_data_source_->RemovePlayoutSink(this); |
| 480 | 487 |
| 481 audio_processing_.reset(); | 488 audio_processing_.reset(); |
| 482 } | 489 } |
| 483 | 490 |
| 484 } // namespace content | 491 } // namespace content |
| OLD | NEW |