OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/audio_input_controller.h" | 5 #include "media/audio/audio_input_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 handler_->OnData(this, data.get()); | 576 handler_->OnData(this, data.get()); |
577 } | 577 } |
578 | 578 |
579 void AudioInputController::DoLogAudioLevels(float level_dbfs, | 579 void AudioInputController::DoLogAudioLevels(float level_dbfs, |
580 int microphone_volume_percent) { | 580 int microphone_volume_percent) { |
581 #if defined(AUDIO_POWER_MONITORING) | 581 #if defined(AUDIO_POWER_MONITORING) |
582 DCHECK(task_runner_->BelongsToCurrentThread()); | 582 DCHECK(task_runner_->BelongsToCurrentThread()); |
583 if (!handler_) | 583 if (!handler_) |
584 return; | 584 return; |
585 | 585 |
| 586 // Detect if the user has enabled hardware mute by pressing the mute |
| 587 // button in audio settings for the selected microphone. |
| 588 const bool microphone_is_muted = stream_->IsMuted(); |
| 589 if (microphone_is_muted) { |
| 590 LogMicrophoneMuteResult(MICROPHONE_IS_MUTED); |
| 591 handler_->OnLog(this, "AIC::OnData: microphone is muted!"); |
| 592 // Return early if microphone is muted. No need to adding logs and UMA stats |
| 593 // of audio levels if we know that the micropone is muted. |
| 594 return; |
| 595 } |
| 596 |
| 597 LogMicrophoneMuteResult(MICROPHONE_IS_NOT_MUTED); |
| 598 |
586 std::string log_string = base::StringPrintf( | 599 std::string log_string = base::StringPrintf( |
587 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); | 600 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); |
588 static const float kSilenceThresholdDBFS = -72.24719896f; | 601 static const float kSilenceThresholdDBFS = -72.24719896f; |
589 if (level_dbfs < kSilenceThresholdDBFS) | 602 if (level_dbfs < kSilenceThresholdDBFS) |
590 log_string += " <=> no audio input!"; | 603 log_string += " <=> low audio input level!"; |
591 handler_->OnLog(this, log_string); | 604 handler_->OnLog(this, log_string); |
592 | 605 |
593 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); | 606 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); |
594 | 607 |
595 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); | 608 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); |
596 log_string = base::StringPrintf( | 609 log_string = base::StringPrintf( |
597 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); | 610 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); |
598 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) | 611 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) |
599 log_string += " <=> low microphone level!"; | 612 log_string += " <=> low microphone level!"; |
600 handler_->OnLog(this, log_string); | 613 handler_->OnLog(this, log_string); |
601 | |
602 // Try to detect if the user has enabled hardware mute by pressing the mute | |
603 // button in audio settings for the selected microphone. The idea here is to | |
604 // detect when all input samples are zeros but the actual volume slider is | |
605 // larger than zero. It should correspond to a hardware mute state. | |
606 if (level_dbfs == -std::numeric_limits<float>::infinity() && | |
607 microphone_volume_percent > 0) { | |
608 LogMicrophoneMuteResult(MICROPHONE_IS_MUTED); | |
609 log_string = base::StringPrintf( | |
610 "AIC::OnData: microphone is muted!"); | |
611 handler_->OnLog(this, log_string); | |
612 } else { | |
613 LogMicrophoneMuteResult(MICROPHONE_IS_NOT_MUTED); | |
614 } | |
615 #endif | 614 #endif |
616 } | 615 } |
617 | 616 |
618 void AudioInputController::OnError(AudioInputStream* stream) { | 617 void AudioInputController::OnError(AudioInputStream* stream) { |
619 // Handle error on the audio-manager thread. | 618 // Handle error on the audio-manager thread. |
620 task_runner_->PostTask(FROM_HERE, base::Bind( | 619 task_runner_->PostTask(FROM_HERE, base::Bind( |
621 &AudioInputController::DoReportError, this)); | 620 &AudioInputController::DoReportError, this)); |
622 } | 621 } |
623 | 622 |
624 void AudioInputController::DoStopCloseAndClearStream() { | 623 void AudioInputController::DoStopCloseAndClearStream() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 } | 666 } |
668 | 667 |
669 void AudioInputController::LogSilenceState(SilenceState value) { | 668 void AudioInputController::LogSilenceState(SilenceState value) { |
670 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", | 669 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
671 value, | 670 value, |
672 SILENCE_STATE_MAX + 1); | 671 SILENCE_STATE_MAX + 1); |
673 } | 672 } |
674 #endif | 673 #endif |
675 | 674 |
676 } // namespace media | 675 } // namespace media |
OLD | NEW |