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" | |
8 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
9 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
10 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
11 #endif | 10 #endif |
12 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
13 #include "content/public/common/content_switches.h" | |
14 #include "content/renderer/media/media_stream_audio_processor_options.h" | 12 #include "content/renderer/media/media_stream_audio_processor_options.h" |
15 #include "content/renderer/media/rtc_media_constraints.h" | 13 #include "content/renderer/media/rtc_media_constraints.h" |
16 #include "content/renderer/media/webrtc_audio_device_impl.h" | 14 #include "content/renderer/media/webrtc_audio_device_impl.h" |
17 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
18 #include "media/base/audio_converter.h" | 16 #include "media/base/audio_converter.h" |
19 #include "media/base/audio_fifo.h" | 17 #include "media/base/audio_fifo.h" |
20 #include "media/base/channel_layout.h" | 18 #include "media/base/channel_layout.h" |
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
22 #include "third_party/libjingle/overrides/init_webrtc.h" | 20 #include "third_party/libjingle/overrides/init_webrtc.h" |
23 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 21 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 base::ThreadChecker thread_checker_; | 197 base::ThreadChecker thread_checker_; |
200 const int source_channels_; // For a DCHECK. | 198 const int source_channels_; // For a DCHECK. |
201 const int source_frames_; // For a DCHECK. | 199 const int source_frames_; // For a DCHECK. |
202 scoped_ptr<media::AudioBus> audio_source_intermediate_; | 200 scoped_ptr<media::AudioBus> audio_source_intermediate_; |
203 scoped_ptr<MediaStreamAudioBus> destination_; | 201 scoped_ptr<MediaStreamAudioBus> destination_; |
204 scoped_ptr<media::AudioFifo> fifo_; | 202 scoped_ptr<media::AudioFifo> fifo_; |
205 // Only used when the FIFO is disabled; | 203 // Only used when the FIFO is disabled; |
206 bool data_available_; | 204 bool data_available_; |
207 }; | 205 }; |
208 | 206 |
209 bool MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() { | |
210 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
211 switches::kDisableAudioTrackProcessing); | |
212 } | |
213 | |
214 MediaStreamAudioProcessor::MediaStreamAudioProcessor( | 207 MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
215 const blink::WebMediaConstraints& constraints, | 208 const blink::WebMediaConstraints& constraints, |
216 int effects, | 209 int effects, |
217 WebRtcPlayoutDataSource* playout_data_source) | 210 WebRtcPlayoutDataSource* playout_data_source) |
218 : render_delay_ms_(0), | 211 : render_delay_ms_(0), |
219 playout_data_source_(playout_data_source), | 212 playout_data_source_(playout_data_source), |
220 audio_mirroring_(false), | 213 audio_mirroring_(false), |
221 typing_detected_(false), | 214 typing_detected_(false), |
222 stopped_(false) { | 215 stopped_(false) { |
223 capture_thread_checker_.DetachFromThread(); | 216 capture_thread_checker_.DetachFromThread(); |
224 render_thread_checker_.DetachFromThread(); | 217 render_thread_checker_.DetachFromThread(); |
225 InitializeAudioProcessingModule(constraints, effects); | 218 InitializeAudioProcessingModule(constraints, effects); |
226 if (IsAudioTrackProcessingEnabled()) { | 219 |
227 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); | 220 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); |
228 // In unit tests not creating a message filter, |aec_dump_message_filter_| | 221 // In unit tests not creating a message filter, |aec_dump_message_filter_| |
229 // will be NULL. We can just ignore that. Other unit tests and browser tests | 222 // will be NULL. We can just ignore that. Other unit tests and browser tests |
230 // ensure that we do get the filter when we should. | 223 // ensure that we do get the filter when we should. |
231 if (aec_dump_message_filter_.get()) | 224 if (aec_dump_message_filter_.get()) |
232 aec_dump_message_filter_->AddDelegate(this); | 225 aec_dump_message_filter_->AddDelegate(this); |
233 } | |
234 } | 226 } |
235 | 227 |
236 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 228 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
237 DCHECK(main_thread_checker_.CalledOnValidThread()); | 229 DCHECK(main_thread_checker_.CalledOnValidThread()); |
238 Stop(); | 230 Stop(); |
239 } | 231 } |
240 | 232 |
241 void MediaStreamAudioProcessor::OnCaptureFormatChanged( | 233 void MediaStreamAudioProcessor::OnCaptureFormatChanged( |
242 const media::AudioParameters& input_format) { | 234 const media::AudioParameters& input_format) { |
243 DCHECK(main_thread_checker_.CalledOnValidThread()); | 235 DCHECK(main_thread_checker_.CalledOnValidThread()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 const blink::WebMediaConstraints& constraints, int effects) { | 384 const blink::WebMediaConstraints& constraints, int effects) { |
393 DCHECK(!audio_processing_); | 385 DCHECK(!audio_processing_); |
394 | 386 |
395 MediaAudioConstraints audio_constraints(constraints, effects); | 387 MediaAudioConstraints audio_constraints(constraints, effects); |
396 | 388 |
397 // Audio mirroring can be enabled even though audio processing is otherwise | 389 // Audio mirroring can be enabled even though audio processing is otherwise |
398 // disabled. | 390 // disabled. |
399 audio_mirroring_ = audio_constraints.GetProperty( | 391 audio_mirroring_ = audio_constraints.GetProperty( |
400 MediaAudioConstraints::kGoogAudioMirroring); | 392 MediaAudioConstraints::kGoogAudioMirroring); |
401 | 393 |
402 if (!IsAudioTrackProcessingEnabled()) { | |
403 RecordProcessingState(AUDIO_PROCESSING_IN_WEBRTC); | |
404 return; | |
405 } | |
406 | |
407 #if defined(OS_IOS) | 394 #if defined(OS_IOS) |
408 // On iOS, VPIO provides built-in AGC and AEC. | 395 // On iOS, VPIO provides built-in AGC and AEC. |
409 const bool echo_cancellation = false; | 396 const bool echo_cancellation = false; |
410 const bool goog_agc = false; | 397 const bool goog_agc = false; |
411 #else | 398 #else |
412 const bool echo_cancellation = | 399 const bool echo_cancellation = |
413 audio_constraints.GetEchoCancellationProperty(); | 400 audio_constraints.GetEchoCancellationProperty(); |
414 const bool goog_agc = audio_constraints.GetProperty( | 401 const bool goog_agc = audio_constraints.GetProperty( |
415 MediaAudioConstraints::kGoogAutoGainControl); | 402 MediaAudioConstraints::kGoogAutoGainControl); |
416 #endif | 403 #endif |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 vad->stream_has_voice()); | 611 vad->stream_has_voice()); |
625 base::subtle::Release_Store(&typing_detected_, detected); | 612 base::subtle::Release_Store(&typing_detected_, detected); |
626 } | 613 } |
627 | 614 |
628 // Return 0 if the volume hasn't been changed, and otherwise the new volume. | 615 // Return 0 if the volume hasn't been changed, and otherwise the new volume. |
629 return (agc->stream_analog_level() == volume) ? | 616 return (agc->stream_analog_level() == volume) ? |
630 0 : agc->stream_analog_level(); | 617 0 : agc->stream_analog_level(); |
631 } | 618 } |
632 | 619 |
633 } // namespace content | 620 } // namespace content |
OLD | NEW |