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" |
| (...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 std::string log_string = base::StringPrintf( | 586 std::string log_string; |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
nit: move this down to where you need it (where pr
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
| |
| 587 | |
| 588 // Detect if the user has enabled hardware mute by pressing the mute | |
| 589 // button in audio settings for the selected microphone. | |
| 590 const bool microphone_is_muted = stream_->IsMuted(); | |
| 591 if (microphone_is_muted) { | |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
nit: you don't really need this variable.
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
| |
| 592 LogMicrophoneMuteResult(MICROPHONE_IS_MUTED); | |
| 593 log_string = base::StringPrintf( | |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
no need for StringPrintf
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
| |
| 594 "AIC::OnData: microphone is muted!"); | |
| 595 handler_->OnLog(this, log_string); | |
| 596 // Return early if microphone is muted. No idea adding logs and UMA stats | |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
nit: "No idea" -> "No need to" (etc)
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
| |
| 597 // of audio levels if we know that the micropone is muted. | |
| 598 return; | |
| 599 } else { | |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
nit: no need for else since there's an early retur
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
| |
| 600 LogMicrophoneMuteResult(MICROPHONE_IS_NOT_MUTED); | |
| 601 } | |
| 602 | |
| 603 log_string = base::StringPrintf( | |
| 587 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); | 604 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); |
| 588 static const float kSilenceThresholdDBFS = -72.24719896f; | 605 static const float kSilenceThresholdDBFS = -72.24719896f; |
| 589 if (level_dbfs < kSilenceThresholdDBFS) | 606 if (level_dbfs < kSilenceThresholdDBFS) |
| 590 log_string += " <=> no audio input!"; | 607 log_string += " <=> no audio input!"; |
| 591 handler_->OnLog(this, log_string); | 608 handler_->OnLog(this, log_string); |
| 592 | 609 |
| 593 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); | 610 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); |
| 594 | 611 |
| 595 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); | 612 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); |
| 596 log_string = base::StringPrintf( | 613 log_string = base::StringPrintf( |
| 597 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); | 614 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent); |
| 598 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) | 615 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent) |
| 599 log_string += " <=> low microphone level!"; | 616 log_string += " <=> low microphone level!"; |
| 600 handler_->OnLog(this, log_string); | 617 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 | 618 #endif |
| 616 } | 619 } |
| 617 | 620 |
| 618 void AudioInputController::OnError(AudioInputStream* stream) { | 621 void AudioInputController::OnError(AudioInputStream* stream) { |
| 619 // Handle error on the audio-manager thread. | 622 // Handle error on the audio-manager thread. |
| 620 task_runner_->PostTask(FROM_HERE, base::Bind( | 623 task_runner_->PostTask(FROM_HERE, base::Bind( |
| 621 &AudioInputController::DoReportError, this)); | 624 &AudioInputController::DoReportError, this)); |
| 622 } | 625 } |
| 623 | 626 |
| 624 void AudioInputController::DoStopCloseAndClearStream() { | 627 void AudioInputController::DoStopCloseAndClearStream() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 } | 670 } |
| 668 | 671 |
| 669 void AudioInputController::LogSilenceState(SilenceState value) { | 672 void AudioInputController::LogSilenceState(SilenceState value) { |
| 670 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", | 673 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
| 671 value, | 674 value, |
| 672 SILENCE_STATE_MAX + 1); | 675 SILENCE_STATE_MAX + 1); |
| 673 } | 676 } |
| 674 #endif | 677 #endif |
| 675 | 678 |
| 676 } // namespace media | 679 } // namespace media |
| OLD | NEW |