Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 582733002: Adds a platform independent detecion of microphone hardware mute (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi@ Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
27 };
28
29 void LogMicrophoneMuteResult(MicrophoneMuteResult result) {
30 UMA_HISTOGRAM_ENUMERATION("Media.MicrophoneMuted",
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
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!");
tommi (sloooow) - chröme 2014/09/19 16:11:07 no need for StringPrintf
henrika (OOO until Aug 14) 2014/09/22 07:34:14 LOL, thx.
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698