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

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

Issue 550933002: Adding media.MicrophoneVolume UMA stat (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build warning 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 | « media/audio/audio_input_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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"
(...skipping 28 matching lines...) Expand all
39 // constant given by |kPowerMeasurementTimeConstantMilliseconds|. 39 // constant given by |kPowerMeasurementTimeConstantMilliseconds|.
40 // Example: fs=44100, ts=10e-3 => alpha~0.022420 40 // Example: fs=44100, ts=10e-3 => alpha~0.022420
41 // fs=44100, ts=20e-3 => alpha~0.165903 41 // fs=44100, ts=20e-3 => alpha~0.165903
42 // A large smoothing factor corresponds to a faster filter response to input 42 // A large smoothing factor corresponds to a faster filter response to input
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
50 // A warning will be logged when the microphone audio volume is below this
51 // threshold.
52 const int kLowLevelMicrophoneLevelPercent = 10;
49 #endif 53 #endif
50 } 54 }
51 55
52 // Used to log the result of capture startup. 56 // Used to log the result of capture startup.
53 // This was previously logged as a boolean with only the no callback and OK 57 // This was previously logged as a boolean with only the no callback and OK
54 // options. The enum order is kept to ensure backwards compatibility. 58 // options. The enum order is kept to ensure backwards compatibility.
55 // Elements in this enum should not be deleted or rearranged; the only 59 // Elements in this enum should not be deleted or rearranged; the only
56 // permitted operation is to add new elements before CAPTURE_STARTUP_RESULT_MAX 60 // permitted operation is to add new elements before CAPTURE_STARTUP_RESULT_MAX
57 // and update CAPTURE_STARTUP_RESULT_MAX. 61 // and update CAPTURE_STARTUP_RESULT_MAX.
58 enum CaptureStartupResult { 62 enum CaptureStartupResult {
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 kPowerMonitorLogIntervalSeconds) { 507 kPowerMonitorLogIntervalSeconds) {
504 // Wrap data into an AudioBus to match AudioPowerMonitor::Scan. 508 // Wrap data into an AudioBus to match AudioPowerMonitor::Scan.
505 // TODO(henrika): remove this section when capture side uses AudioBus. 509 // TODO(henrika): remove this section when capture side uses AudioBus.
506 // See http://crbug.com/375155 for details. 510 // See http://crbug.com/375155 for details.
507 audio_level_->Scan(*source, source->frames()); 511 audio_level_->Scan(*source, source->frames());
508 512
509 // Get current average power level and add it to the log. 513 // Get current average power level and add it to the log.
510 // Possible range is given by [-inf, 0] dBFS. 514 // Possible range is given by [-inf, 0] dBFS.
511 std::pair<float, bool> result = audio_level_->ReadCurrentPowerAndClip(); 515 std::pair<float, bool> result = audio_level_->ReadCurrentPowerAndClip();
512 516
517 // Add current microphone volume to log and UMA histogram.
518 const int mic_volume_percent = static_cast<int>(100.0 * volume);
519
513 // Use event handler on the audio thread to relay a message to the ARIH 520 // Use event handler on the audio thread to relay a message to the ARIH
514 // in content which does the actual logging on the IO thread. 521 // in content which does the actual logging on the IO thread.
515 task_runner_->PostTask( 522 task_runner_->PostTask(FROM_HERE,
516 FROM_HERE, 523 base::Bind(&AudioInputController::DoLogAudioLevels,
517 base::Bind( 524 this,
518 &AudioInputController::DoLogAudioLevel, this, result.first)); 525 result.first,
526 mic_volume_percent));
519 527
520 last_audio_level_log_time_ = base::TimeTicks::Now(); 528 last_audio_level_log_time_ = base::TimeTicks::Now();
521 529
522 // Reset the average power level (since we don't log continuously). 530 // Reset the average power level (since we don't log continuously).
523 audio_level_->Reset(); 531 audio_level_->Reset();
524 } 532 }
525 #endif 533 #endif
526 return; 534 return;
527 } 535 }
528 536
(...skipping 11 matching lines...) Expand all
540 base::Bind( 548 base::Bind(
541 &AudioInputController::DoOnData, this, base::Passed(&audio_data))); 549 &AudioInputController::DoOnData, this, base::Passed(&audio_data)));
542 } 550 }
543 551
544 void AudioInputController::DoOnData(scoped_ptr<AudioBus> data) { 552 void AudioInputController::DoOnData(scoped_ptr<AudioBus> data) {
545 DCHECK(task_runner_->BelongsToCurrentThread()); 553 DCHECK(task_runner_->BelongsToCurrentThread());
546 if (handler_) 554 if (handler_)
547 handler_->OnData(this, data.get()); 555 handler_->OnData(this, data.get());
548 } 556 }
549 557
550 void AudioInputController::DoLogAudioLevel(float level_dbfs) { 558 void AudioInputController::DoLogAudioLevels(float level_dbfs,
559 int microphone_volume_percent) {
551 #if defined(AUDIO_POWER_MONITORING) 560 #if defined(AUDIO_POWER_MONITORING)
552 DCHECK(task_runner_->BelongsToCurrentThread()); 561 DCHECK(task_runner_->BelongsToCurrentThread());
553 if (!handler_) 562 if (!handler_)
554 return; 563 return;
555 564
556 std::string log_string = base::StringPrintf( 565 std::string log_string = base::StringPrintf(
557 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); 566 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs);
558 static const float kSilenceThresholdDBFS = -72.24719896f; 567 static const float kSilenceThresholdDBFS = -72.24719896f;
559 if (level_dbfs < kSilenceThresholdDBFS) 568 if (level_dbfs < kSilenceThresholdDBFS)
560 log_string += " <=> no audio input!"; 569 log_string += " <=> no audio input!";
561 handler_->OnLog(this, log_string); 570 handler_->OnLog(this, log_string);
562 571
563 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); 572 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS);
573
574 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent);
575 log_string = base::StringPrintf(
576 "AIC::OnData: microphone volume=%d%%", microphone_volume_percent);
577 if (microphone_volume_percent < kLowLevelMicrophoneLevelPercent)
578 log_string += " <=> low microphone level!";
579 handler_->OnLog(this, log_string);
564 #endif 580 #endif
565 } 581 }
566 582
567 void AudioInputController::OnError(AudioInputStream* stream) { 583 void AudioInputController::OnError(AudioInputStream* stream) {
568 // Handle error on the audio-manager thread. 584 // Handle error on the audio-manager thread.
569 task_runner_->PostTask(FROM_HERE, base::Bind( 585 task_runner_->PostTask(FROM_HERE, base::Bind(
570 &AudioInputController::DoReportError, this)); 586 &AudioInputController::DoReportError, this));
571 } 587 }
572 588
573 void AudioInputController::DoStopCloseAndClearStream() { 589 void AudioInputController::DoStopCloseAndClearStream() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 632 }
617 633
618 void AudioInputController::LogSilenceState(SilenceState value) { 634 void AudioInputController::LogSilenceState(SilenceState value) {
619 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", 635 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
620 value, 636 value,
621 SILENCE_STATE_MAX + 1); 637 SILENCE_STATE_MAX + 1);
622 } 638 }
623 #endif 639 #endif
624 640
625 } // namespace media 641 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698