Chromium Code Reviews| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
| 13 #include "media/base/limits.h" | |
| 14 #include "media/base/scoped_histogram_timer.h" | 13 #include "media/base/scoped_histogram_timer.h" |
| 15 #include "media/base/user_input_monitor.h" | 14 #include "media/base/user_input_monitor.h" |
| 16 | 15 |
| 17 using base::TimeDelta; | 16 using base::TimeDelta; |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 19 | |
| 20 // Logs if the user has enabled the microphone mute or not. This is normally | |
| 21 // done by marking a checkbox in an audio-settings UI which is unique for each | |
| 22 // platform. Elements in this enum should not be added, deleted or rearranged. | |
| 23 enum MicrophoneMuteResult { | |
| 24 MICROPHONE_IS_MUTED = 0, | |
| 25 MICROPHONE_IS_NOT_MUTED = 1, | |
| 26 MICROPHONE_MUTE_MAX = MICROPHONE_IS_NOT_MUTED | |
|
no longer working on chromium
2014/09/22 10:16:35
If you change MICROPHONE_MUTE_MAX = MICROPHONE_IS_
henrika (OOO until Aug 14)
2014/09/22 11:24:13
Found this style in other places in Chrome. Feels
no longer working on chromium
2014/09/23 08:17:58
I think the most common style is
enum MicrophoneMu
| |
| 27 }; | |
| 28 | |
| 29 void LogMicrophoneMuteResult(MicrophoneMuteResult result) { | |
| 30 UMA_HISTOGRAM_ENUMERATION("Media.MicrophoneMuted", | |
|
no longer working on chromium
2014/09/22 10:16:35
what is the follow-up after we get the muted or un
henrika (OOO until Aug 14)
2014/09/22 11:24:13
The idea is that we shall learn how many users act
| |
| 31 result, | |
| 32 MICROPHONE_MUTE_MAX + 1); | |
| 33 } | |
| 34 | |
| 20 const int kMaxInputChannels = 3; | 35 const int kMaxInputChannels = 3; |
| 21 | 36 |
| 22 // TODO(henrika): remove usage of timers and add support for proper | 37 // TODO(henrika): remove usage of timers and add support for proper |
| 23 // notification of when the input device is removed. This was originally added | 38 // notification of when the input device is removed. This was originally added |
| 24 // to resolve http://crbug.com/79936 for Windows platforms. This then caused | 39 // to resolve http://crbug.com/79936 for Windows platforms. This then caused |
| 25 // breakage (very hard to repro bugs!) on other platforms: See | 40 // breakage (very hard to repro bugs!) on other platforms: See |
| 26 // http://crbug.com/226327 and http://crbug.com/230972. | 41 // http://crbug.com/226327 and http://crbug.com/230972. |
| 27 // See also that the timer has been disabled on Mac now due to | 42 // See also that the timer has been disabled on Mac now due to |
| 28 // crbug.com/357501. | 43 // crbug.com/357501. |
| 29 const int kTimerResetIntervalSeconds = 1; | 44 const int kTimerResetIntervalSeconds = 1; |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 handler_->OnLog(this, log_string); | 585 handler_->OnLog(this, log_string); |
| 571 | 586 |
| 572 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); | 587 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); |
| 573 | 588 |
| 574 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); | 589 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); |
| 575 log_string = base::StringPrintf( | 590 log_string = base::StringPrintf( |
| 576 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); | 591 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); |
| 577 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) | 592 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) |
| 578 log_string += " <=> low microphone level!"; | 593 log_string += " <=> low microphone level!"; |
| 579 handler_->OnLog(this, log_string); | 594 handler_->OnLog(this, log_string); |
| 595 | |
| 596 // Try to detect if the user has enabled hardware mute by pressing the mute | |
| 597 // button in audio settings for the selected microphone. The idea here is to | |
| 598 // detect when all input samples are zeros but the actual volume slider is | |
| 599 // larger than zero. It should correspond to a hardware mute state. | |
| 600 if (level_dbfs == -std::numeric_limits<float>::infinity() && | |
| 601 microphone_volume_percent > 0) { | |
| 602 LogMicrophoneMuteResult(MICROPHONE_IS_MUTED); | |
| 603 log_string = "AIC::OnData: microphone is muted!"; | |
| 604 handler_->OnLog(this, log_string); | |
| 605 } else { | |
| 606 LogMicrophoneMuteResult(MICROPHONE_IS_NOT_MUTED); | |
| 607 } | |
| 580 #endif | 608 #endif |
| 581 } | 609 } |
| 582 | 610 |
| 583 void AudioInputController::OnError(AudioInputStream* stream) { | 611 void AudioInputController::OnError(AudioInputStream* stream) { |
| 584 // Handle error on the audio-manager thread. | 612 // Handle error on the audio-manager thread. |
| 585 task_runner_->PostTask(FROM_HERE, base::Bind( | 613 task_runner_->PostTask(FROM_HERE, base::Bind( |
| 586 &AudioInputController::DoReportError, this)); | 614 &AudioInputController::DoReportError, this)); |
| 587 } | 615 } |
| 588 | 616 |
| 589 void AudioInputController::DoStopCloseAndClearStream() { | 617 void AudioInputController::DoStopCloseAndClearStream() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 } | 660 } |
| 633 | 661 |
| 634 void AudioInputController::LogSilenceState(SilenceState value) { | 662 void AudioInputController::LogSilenceState(SilenceState value) { |
| 635 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", | 663 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
| 636 value, | 664 value, |
| 637 SILENCE_STATE_MAX + 1); | 665 SILENCE_STATE_MAX + 1); |
| 638 } | 666 } |
| 639 #endif | 667 #endif |
| 640 | 668 |
| 641 } // namespace media | 669 } // namespace media |
| OLD | NEW |