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 const int kMaxInputChannels = 3; | 20 const int kMaxInputChannels = 3; |
21 | 21 |
22 // TODO(henrika): remove usage of timers and add support for proper | 22 // TODO(henrika): remove usage of timers and add support for proper |
23 // notification of when the input device is removed. This was originally added | 23 // 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 | 24 // to resolve http://crbug.com/79936 for Windows platforms. This then caused |
25 // breakage (very hard to repro bugs!) on other platforms: See | 25 // breakage (very hard to repro bugs!) on other platforms: See |
26 // http://crbug.com/226327 and http://crbug.com/230972. | 26 // http://crbug.com/226327 and http://crbug.com/230972. |
27 // See also that the timer has been disabled on Mac now due to | 27 // See also that the timer has been disabled on Mac now due to |
28 // crbug.com/357501. | 28 // crbug.com/357501. |
29 const int kTimerResetIntervalSeconds = 1; | 29 const int kTimerResetIntervalSeconds = 1; |
(...skipping 13 matching lines...) Expand all Loading... |
43 // changes since y(n)=alpha*x(n)+(1-alpha)*y(n-1), where x(n) is the input | 43 // changes since y(n)=alpha*x(n)+(1-alpha)*y(n-1), where x(n) is the input |
44 // and y(n) is the output. | 44 // and y(n) is the output. |
45 const int kPowerMeasurementTimeConstantMilliseconds = 10; | 45 const int kPowerMeasurementTimeConstantMilliseconds = 10; |
46 | 46 |
47 // Time in seconds between two successive measurements of audio power levels. | 47 // Time in seconds between two successive measurements of audio power levels. |
48 const int kPowerMonitorLogIntervalSeconds = 15; | 48 const int kPowerMonitorLogIntervalSeconds = 15; |
49 | 49 |
50 // A warning will be logged when the microphone audio volume is below this | 50 // A warning will be logged when the microphone audio volume is below this |
51 // threshold. | 51 // threshold. |
52 const int kLowLevelMicrophoneLevelPercent = 10; | 52 const int kLowLevelMicrophoneLevelPercent = 10; |
| 53 |
| 54 // Logs if the user has enabled the microphone mute or not. This is normally |
| 55 // done by marking a checkbox in an audio-settings UI which is unique for each |
| 56 // platform. Elements in this enum should not be added, deleted or rearranged. |
| 57 enum MicrophoneMuteResult { |
| 58 MICROPHONE_IS_MUTED = 0, |
| 59 MICROPHONE_IS_NOT_MUTED = 1, |
| 60 MICROPHONE_MUTE_MAX = MICROPHONE_IS_NOT_MUTED |
| 61 }; |
| 62 |
| 63 void LogMicrophoneMuteResult(MicrophoneMuteResult result) { |
| 64 UMA_HISTOGRAM_ENUMERATION("Media.MicrophoneMuted", |
| 65 result, |
| 66 MICROPHONE_MUTE_MAX + 1); |
| 67 } |
53 #endif | 68 #endif |
54 } | 69 } |
55 | 70 |
56 // Used to log the result of capture startup. | 71 // Used to log the result of capture startup. |
57 // This was previously logged as a boolean with only the no callback and OK | 72 // This was previously logged as a boolean with only the no callback and OK |
58 // options. The enum order is kept to ensure backwards compatibility. | 73 // options. The enum order is kept to ensure backwards compatibility. |
59 // Elements in this enum should not be deleted or rearranged; the only | 74 // Elements in this enum should not be deleted or rearranged; the only |
60 // permitted operation is to add new elements before CAPTURE_STARTUP_RESULT_MAX | 75 // permitted operation is to add new elements before CAPTURE_STARTUP_RESULT_MAX |
61 // and update CAPTURE_STARTUP_RESULT_MAX. | 76 // and update CAPTURE_STARTUP_RESULT_MAX. |
62 enum CaptureStartupResult { | 77 enum CaptureStartupResult { |
(...skipping 507 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 = base::StringPrintf( |
| 604 "AIC::OnData: microphone is muted!"); |
| 605 handler_->OnLog(this, log_string); |
| 606 } else { |
| 607 LogMicrophoneMuteResult(MICROPHONE_IS_NOT_MUTED); |
| 608 } |
580 #endif | 609 #endif |
581 } | 610 } |
582 | 611 |
583 void AudioInputController::OnError(AudioInputStream* stream) { | 612 void AudioInputController::OnError(AudioInputStream* stream) { |
584 // Handle error on the audio-manager thread. | 613 // Handle error on the audio-manager thread. |
585 task_runner_->PostTask(FROM_HERE, base::Bind( | 614 task_runner_->PostTask(FROM_HERE, base::Bind( |
586 &AudioInputController::DoReportError, this)); | 615 &AudioInputController::DoReportError, this)); |
587 } | 616 } |
588 | 617 |
589 void AudioInputController::DoStopCloseAndClearStream() { | 618 void AudioInputController::DoStopCloseAndClearStream() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } | 661 } |
633 | 662 |
634 void AudioInputController::LogSilenceState(SilenceState value) { | 663 void AudioInputController::LogSilenceState(SilenceState value) { |
635 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", | 664 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
636 value, | 665 value, |
637 SILENCE_STATE_MAX + 1); | 666 SILENCE_STATE_MAX + 1); |
638 } | 667 } |
639 #endif | 668 #endif |
640 | 669 |
641 } // namespace media | 670 } // namespace media |
OLD | NEW |