| 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 aec_dump_message_filter_->AddDelegate(this); |
| 183 } |
| 180 } | 184 } |
| 181 | 185 |
| 182 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { | 186 MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
| 183 DCHECK(main_thread_checker_.CalledOnValidThread()); | 187 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 188 if (aec_dump_message_filter_) { |
| 189 aec_dump_message_filter_->RemoveDelegate(this); |
| 190 aec_dump_message_filter_ = NULL; |
| 191 } |
| 184 StopAudioProcessing(); | 192 StopAudioProcessing(); |
| 185 } | 193 } |
| 186 | 194 |
| 187 void MediaStreamAudioProcessor::OnCaptureFormatChanged( | 195 void MediaStreamAudioProcessor::OnCaptureFormatChanged( |
| 188 const media::AudioParameters& source_params) { | 196 const media::AudioParameters& source_params) { |
| 189 DCHECK(main_thread_checker_.CalledOnValidThread()); | 197 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 190 // There is no need to hold a lock here since the caller guarantees that | 198 // There is no need to hold a lock here since the caller guarantees that |
| 191 // there is no more PushCaptureData() and ProcessAndConsumeData() callbacks | 199 // there is no more PushCaptureData() and ProcessAndConsumeData() callbacks |
| 192 // on the capture thread. | 200 // on the capture thread. |
| 193 InitializeCaptureConverter(source_params); | 201 InitializeCaptureConverter(source_params); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 239 } |
| 232 | 240 |
| 233 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { | 241 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { |
| 234 return capture_converter_->source_parameters(); | 242 return capture_converter_->source_parameters(); |
| 235 } | 243 } |
| 236 | 244 |
| 237 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { | 245 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { |
| 238 return capture_converter_->sink_parameters(); | 246 return capture_converter_->sink_parameters(); |
| 239 } | 247 } |
| 240 | 248 |
| 241 void MediaStreamAudioProcessor::StartAecDump(base::File aec_dump_file) { | 249 void MediaStreamAudioProcessor::OnAecDumpFile( |
| 250 const IPC::PlatformFileForTransit& file_handle) { |
| 251 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 252 |
| 253 base::File file = IPC::PlatformFileForTransitToFile(file_handle); |
| 254 DCHECK(file.IsValid()); |
| 255 |
| 242 if (audio_processing_) | 256 if (audio_processing_) |
| 243 StartEchoCancellationDump(audio_processing_.get(), aec_dump_file.Pass()); | 257 StartEchoCancellationDump(audio_processing_.get(), file.Pass()); |
| 258 else |
| 259 file.Close(); |
| 244 } | 260 } |
| 245 | 261 |
| 246 void MediaStreamAudioProcessor::StopAecDump() { | 262 void MediaStreamAudioProcessor::OnDisableAecDump() { |
| 263 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 247 if (audio_processing_) | 264 if (audio_processing_) |
| 248 StopEchoCancellationDump(audio_processing_.get()); | 265 StopEchoCancellationDump(audio_processing_.get()); |
| 249 } | 266 } |
| 250 | 267 |
| 268 void MediaStreamAudioProcessor::OnIpcClosing() { |
| 269 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 270 aec_dump_message_filter_ = NULL; |
| 271 } |
| 272 |
| 251 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, | 273 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
| 252 int sample_rate, | 274 int sample_rate, |
| 253 int audio_delay_milliseconds) { | 275 int audio_delay_milliseconds) { |
| 254 DCHECK(render_thread_checker_.CalledOnValidThread()); | 276 DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 255 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ | 277 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ |
| 256 audio_processing_->echo_cancellation()->is_enabled()); | 278 audio_processing_->echo_cancellation()->is_enabled()); |
| 257 | 279 |
| 258 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); | 280 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); |
| 259 DCHECK_LT(audio_delay_milliseconds, | 281 DCHECK_LT(audio_delay_milliseconds, |
| 260 std::numeric_limits<base::subtle::Atomic32>::max()); | 282 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 | 509 // Return 0 if the volume has not been changed, otherwise return the new |
| 488 // volume. | 510 // volume. |
| 489 return (agc->stream_analog_level() == volume) ? | 511 return (agc->stream_analog_level() == volume) ? |
| 490 0 : agc->stream_analog_level(); | 512 0 : agc->stream_analog_level(); |
| 491 } | 513 } |
| 492 | 514 |
| 493 void MediaStreamAudioProcessor::StopAudioProcessing() { | 515 void MediaStreamAudioProcessor::StopAudioProcessing() { |
| 494 if (!audio_processing_.get()) | 516 if (!audio_processing_.get()) |
| 495 return; | 517 return; |
| 496 | 518 |
| 497 StopAecDump(); | 519 StopEchoCancellationDump(audio_processing_.get()); |
| 498 | 520 |
| 499 if (playout_data_source_) | 521 if (playout_data_source_) |
| 500 playout_data_source_->RemovePlayoutSink(this); | 522 playout_data_source_->RemovePlayoutSink(this); |
| 501 | 523 |
| 502 audio_processing_.reset(); | 524 audio_processing_.reset(); |
| 503 } | 525 } |
| 504 | 526 |
| 505 } // namespace content | 527 } // namespace content |
| OLD | NEW |