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/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const blink::WebMediaConstraints& constraints, | 170 const blink::WebMediaConstraints& constraints, |
171 int effects, | 171 int effects, |
172 WebRtcPlayoutDataSource* playout_data_source) | 172 WebRtcPlayoutDataSource* playout_data_source) |
173 : render_delay_ms_(0), | 173 : render_delay_ms_(0), |
174 playout_data_source_(playout_data_source), | 174 playout_data_source_(playout_data_source), |
175 audio_mirroring_(false), | 175 audio_mirroring_(false), |
176 typing_detected_(false) { | 176 typing_detected_(false) { |
177 capture_thread_checker_.DetachFromThread(); | 177 capture_thread_checker_.DetachFromThread(); |
178 render_thread_checker_.DetachFromThread(); | 178 render_thread_checker_.DetachFromThread(); |
179 InitializeAudioProcessingModule(constraints, effects); | 179 InitializeAudioProcessingModule(constraints, effects); |
| 180 if (IsAudioTrackProcessingEnabled()) { |
| 181 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); |
| 182 // In unit tests not creating a message filter, |aec_dump_message_filter_| |
| 183 // will be NULL. We can just ignore that. Other unit tests and browser tests |
| 184 // ensure that we do get the filter when we should. |
| 185 if (aec_dump_message_filter_) |
| 186 aec_dump_message_filter_->AddDelegate(this); |
| 187 } |
180 } | 188 } |
181 | 189 |
182 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 190 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
183 DCHECK(main_thread_checker_.CalledOnValidThread()); | 191 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 192 if (aec_dump_message_filter_) { |
| 193 aec_dump_message_filter_->RemoveDelegate(this); |
| 194 aec_dump_message_filter_ = NULL; |
| 195 } |
184 StopAudioProcessing(); | 196 StopAudioProcessing(); |
185 } | 197 } |
186 | 198 |
187 void MediaStreamAudioProcessor::OnCaptureFormatChanged( | 199 void MediaStreamAudioProcessor::OnCaptureFormatChanged( |
188 const media::AudioParameters& source_params) { | 200 const media::AudioParameters& source_params) { |
189 DCHECK(main_thread_checker_.CalledOnValidThread()); | 201 DCHECK(main_thread_checker_.CalledOnValidThread()); |
190 // There is no need to hold a lock here since the caller guarantees that | 202 // There is no need to hold a lock here since the caller guarantees that |
191 // there is no more PushCaptureData() and ProcessAndConsumeData() callbacks | 203 // there is no more PushCaptureData() and ProcessAndConsumeData() callbacks |
192 // on the capture thread. | 204 // on the capture thread. |
193 InitializeCaptureConverter(source_params); | 205 InitializeCaptureConverter(source_params); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 243 } |
232 | 244 |
233 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { | 245 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { |
234 return capture_converter_->source_parameters(); | 246 return capture_converter_->source_parameters(); |
235 } | 247 } |
236 | 248 |
237 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { | 249 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { |
238 return capture_converter_->sink_parameters(); | 250 return capture_converter_->sink_parameters(); |
239 } | 251 } |
240 | 252 |
241 void MediaStreamAudioProcessor::StartAecDump(base::File aec_dump_file) { | 253 void MediaStreamAudioProcessor::OnAecDumpFile( |
| 254 const IPC::PlatformFileForTransit& file_handle) { |
| 255 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 256 |
| 257 base::File file = IPC::PlatformFileForTransitToFile(file_handle); |
| 258 DCHECK(file.IsValid()); |
| 259 |
242 if (audio_processing_) | 260 if (audio_processing_) |
243 StartEchoCancellationDump(audio_processing_.get(), aec_dump_file.Pass()); | 261 StartEchoCancellationDump(audio_processing_.get(), file.Pass()); |
| 262 else |
| 263 file.Close(); |
244 } | 264 } |
245 | 265 |
246 void MediaStreamAudioProcessor::StopAecDump() { | 266 void MediaStreamAudioProcessor::OnDisableAecDump() { |
| 267 DCHECK(main_thread_checker_.CalledOnValidThread()); |
247 if (audio_processing_) | 268 if (audio_processing_) |
248 StopEchoCancellationDump(audio_processing_.get()); | 269 StopEchoCancellationDump(audio_processing_.get()); |
249 } | 270 } |
250 | 271 |
| 272 void MediaStreamAudioProcessor::OnIpcClosing() { |
| 273 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 274 aec_dump_message_filter_ = NULL; |
| 275 } |
| 276 |
251 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, | 277 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
252 int sample_rate, | 278 int sample_rate, |
253 int audio_delay_milliseconds) { | 279 int audio_delay_milliseconds) { |
254 DCHECK(render_thread_checker_.CalledOnValidThread()); | 280 DCHECK(render_thread_checker_.CalledOnValidThread()); |
255 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ | 281 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ |
256 audio_processing_->echo_cancellation()->is_enabled()); | 282 audio_processing_->echo_cancellation()->is_enabled()); |
257 | 283 |
258 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); | 284 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); |
259 DCHECK_LT(audio_delay_milliseconds, | 285 DCHECK_LT(audio_delay_milliseconds, |
260 std::numeric_limits<base::subtle::Atomic32>::max()); | 286 std::numeric_limits<base::subtle::Atomic32>::max()); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // Return 0 if the volume has not been changed, otherwise return the new | 513 // Return 0 if the volume has not been changed, otherwise return the new |
488 // volume. | 514 // volume. |
489 return (agc->stream_analog_level() == volume) ? | 515 return (agc->stream_analog_level() == volume) ? |
490 0 : agc->stream_analog_level(); | 516 0 : agc->stream_analog_level(); |
491 } | 517 } |
492 | 518 |
493 void MediaStreamAudioProcessor::StopAudioProcessing() { | 519 void MediaStreamAudioProcessor::StopAudioProcessing() { |
494 if (!audio_processing_.get()) | 520 if (!audio_processing_.get()) |
495 return; | 521 return; |
496 | 522 |
497 StopAecDump(); | 523 StopEchoCancellationDump(audio_processing_.get()); |
498 | 524 |
499 if (playout_data_source_) | 525 if (playout_data_source_) |
500 playout_data_source_->RemovePlayoutSink(this); | 526 playout_data_source_->RemovePlayoutSink(this); |
501 | 527 |
502 audio_processing_.reset(); | 528 audio_processing_.reset(); |
503 } | 529 } |
504 | 530 |
505 } // namespace content | 531 } // namespace content |
OLD | NEW |