| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // to Consume(). Only used when the FIFO is disabled. | 280 // to Consume(). Only used when the FIFO is disabled. |
| 281 bool data_available_; | 281 bool data_available_; |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 MediaStreamAudioProcessor::MediaStreamAudioProcessor( | 284 MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
| 285 const blink::WebMediaConstraints& constraints, | 285 const blink::WebMediaConstraints& constraints, |
| 286 const MediaStreamDevice::AudioDeviceParameters& input_params, | 286 const MediaStreamDevice::AudioDeviceParameters& input_params, |
| 287 WebRtcPlayoutDataSource* playout_data_source) | 287 WebRtcPlayoutDataSource* playout_data_source) |
| 288 : render_delay_ms_(0), | 288 : render_delay_ms_(0), |
| 289 playout_data_source_(playout_data_source), | 289 playout_data_source_(playout_data_source), |
| 290 main_thread_message_loop_(base::MessageLoop::current()), |
| 290 audio_mirroring_(false), | 291 audio_mirroring_(false), |
| 291 typing_detected_(false), | 292 typing_detected_(false), |
| 292 stopped_(false) { | 293 stopped_(false) { |
| 293 capture_thread_checker_.DetachFromThread(); | 294 capture_thread_checker_.DetachFromThread(); |
| 294 render_thread_checker_.DetachFromThread(); | 295 render_thread_checker_.DetachFromThread(); |
| 295 InitializeAudioProcessingModule(constraints, input_params); | 296 InitializeAudioProcessingModule(constraints, input_params); |
| 296 | 297 |
| 297 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); | 298 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); |
| 298 // In unit tests not creating a message filter, |aec_dump_message_filter_| | 299 // In unit tests not creating a message filter, |aec_dump_message_filter_| |
| 299 // will be NULL. We can just ignore that. Other unit tests and browser tests | 300 // will be NULL. We can just ignore that. Other unit tests and browser tests |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 output_bus->bus()->SwapChannels(0, 1); | 383 output_bus->bus()->SwapChannels(0, 1); |
| 383 } | 384 } |
| 384 | 385 |
| 385 *processed_data = output_bus->bus(); | 386 *processed_data = output_bus->bus(); |
| 386 | 387 |
| 387 return true; | 388 return true; |
| 388 } | 389 } |
| 389 | 390 |
| 390 void MediaStreamAudioProcessor::Stop() { | 391 void MediaStreamAudioProcessor::Stop() { |
| 391 DCHECK(main_thread_checker_.CalledOnValidThread()); | 392 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 393 |
| 392 if (stopped_) | 394 if (stopped_) |
| 393 return; | 395 return; |
| 394 | 396 |
| 395 stopped_ = true; | 397 stopped_ = true; |
| 396 | 398 |
| 397 if (aec_dump_message_filter_.get()) { | 399 if (aec_dump_message_filter_.get()) { |
| 398 aec_dump_message_filter_->RemoveDelegate(this); | 400 aec_dump_message_filter_->RemoveDelegate(this); |
| 399 aec_dump_message_filter_ = NULL; | 401 aec_dump_message_filter_ = NULL; |
| 400 } | 402 } |
| 401 | 403 |
| 402 if (!audio_processing_.get()) | 404 if (!audio_processing_.get()) |
| 403 return; | 405 return; |
| 404 | 406 |
| 405 audio_processing_.get()->UpdateHistogramsOnCallEnd(); | 407 audio_processing_.get()->UpdateHistogramsOnCallEnd(); |
| 406 StopEchoCancellationDump(audio_processing_.get()); | 408 StopEchoCancellationDump(audio_processing_.get()); |
| 407 | 409 |
| 408 if (playout_data_source_) { | 410 if (playout_data_source_) { |
| 409 playout_data_source_->RemovePlayoutSink(this); | 411 playout_data_source_->RemovePlayoutSink(this); |
| 410 playout_data_source_ = NULL; | 412 playout_data_source_ = NULL; |
| 411 } | 413 } |
| 414 |
| 415 if (echo_information_) |
| 416 echo_information_->ReportAndResetAecDivergentFilterStats(); |
| 412 } | 417 } |
| 413 | 418 |
| 414 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { | 419 const media::AudioParameters& MediaStreamAudioProcessor::InputFormat() const { |
| 415 return input_format_; | 420 return input_format_; |
| 416 } | 421 } |
| 417 | 422 |
| 418 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { | 423 const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { |
| 419 return output_format_; | 424 return output_format_; |
| 420 } | 425 } |
| 421 | 426 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; | 754 DCHECK_EQ(err, 0) << "ProcessStream() error: " << err; |
| 750 | 755 |
| 751 if (typing_detector_) { | 756 if (typing_detector_) { |
| 752 webrtc::VoiceDetection* vad = ap->voice_detection(); | 757 webrtc::VoiceDetection* vad = ap->voice_detection(); |
| 753 DCHECK(vad->is_enabled()); | 758 DCHECK(vad->is_enabled()); |
| 754 bool detected = typing_detector_->Process(key_pressed, | 759 bool detected = typing_detector_->Process(key_pressed, |
| 755 vad->stream_has_voice()); | 760 vad->stream_has_voice()); |
| 756 base::subtle::Release_Store(&typing_detected_, detected); | 761 base::subtle::Release_Store(&typing_detected_, detected); |
| 757 } | 762 } |
| 758 | 763 |
| 759 if (echo_information_) { | 764 main_thread_message_loop_->PostTask( |
| 760 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); | 765 FROM_HERE, base::Bind(&MediaStreamAudioProcessor::UpdateAecStats, this)); |
| 761 } | |
| 762 | 766 |
| 763 // Return 0 if the volume hasn't been changed, and otherwise the new volume. | 767 // Return 0 if the volume hasn't been changed, and otherwise the new volume. |
| 764 return (agc->stream_analog_level() == volume) ? | 768 return (agc->stream_analog_level() == volume) ? |
| 765 0 : agc->stream_analog_level(); | 769 0 : agc->stream_analog_level(); |
| 766 } | 770 } |
| 767 | 771 |
| 772 void MediaStreamAudioProcessor::UpdateAecStats() { |
| 773 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 774 if (echo_information_) |
| 775 echo_information_->UpdateAecStats(audio_processing_->echo_cancellation()); |
| 776 } |
| 777 |
| 768 } // namespace content | 778 } // namespace content |
| OLD | NEW |