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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 kPowerMonitorLogIntervalSeconds) { | 503 kPowerMonitorLogIntervalSeconds) { |
| 504 // Wrap data into an AudioBus to match AudioPowerMonitor::Scan. | 504 // Wrap data into an AudioBus to match AudioPowerMonitor::Scan. |
| 505 // TODO(henrika): remove this section when capture side uses AudioBus. | 505 // TODO(henrika): remove this section when capture side uses AudioBus. |
| 506 // See http://crbug.com/375155 for details. | 506 // See http://crbug.com/375155 for details. |
| 507 audio_level_->Scan(*source, source->frames()); | 507 audio_level_->Scan(*source, source->frames()); |
| 508 | 508 |
| 509 // Get current average power level and add it to the log. | 509 // Get current average power level and add it to the log. |
| 510 // Possible range is given by [-inf, 0] dBFS. | 510 // Possible range is given by [-inf, 0] dBFS. |
| 511 std::pair<float, bool> result = audio_level_->ReadCurrentPowerAndClip(); | 511 std::pair<float, bool> result = audio_level_->ReadCurrentPowerAndClip(); |
| 512 | 512 |
| 513 // Add current microphone volume to log and UMA histogram. | |
| 514 int mic_volume_percent = static_cast<int>(100.0 * volume); | |
|
no longer working on chromium
2014/09/08 13:36:34
why can't we log it as a float?
henrika (OOO until Aug 14)
2014/09/08 13:50:57
It seems to be the preferred style to use int here
no longer working on chromium
2014/09/09 08:21:11
Acknowledged.
| |
| 515 | |
| 513 // Use event handler on the audio thread to relay a message to the ARIH | 516 // 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. | 517 // in content which does the actual logging on the IO thread. |
| 515 task_runner_->PostTask( | 518 task_runner_->PostTask(FROM_HERE, |
| 516 FROM_HERE, | 519 base::Bind(&AudioInputController::DoLogAudioLevels, |
| 517 base::Bind( | 520 this, |
| 518 &AudioInputController::DoLogAudioLevel, this, result.first)); | 521 result.first, |
| 522 mic_volume_percent)); | |
| 519 | 523 |
| 520 last_audio_level_log_time_ = base::TimeTicks::Now(); | 524 last_audio_level_log_time_ = base::TimeTicks::Now(); |
| 521 | 525 |
| 522 // Reset the average power level (since we don't log continuously). | 526 // Reset the average power level (since we don't log continuously). |
| 523 audio_level_->Reset(); | 527 audio_level_->Reset(); |
| 524 } | 528 } |
| 525 #endif | 529 #endif |
| 526 return; | 530 return; |
| 527 } | 531 } |
| 528 | 532 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 540 base::Bind( | 544 base::Bind( |
| 541 &AudioInputController::DoOnData, this, base::Passed(&audio_data))); | 545 &AudioInputController::DoOnData, this, base::Passed(&audio_data))); |
| 542 } | 546 } |
| 543 | 547 |
| 544 void AudioInputController::DoOnData(scoped_ptr<AudioBus> data) { | 548 void AudioInputController::DoOnData(scoped_ptr<AudioBus> data) { |
| 545 DCHECK(task_runner_->BelongsToCurrentThread()); | 549 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 546 if (handler_) | 550 if (handler_) |
| 547 handler_->OnData(this, data.get()); | 551 handler_->OnData(this, data.get()); |
| 548 } | 552 } |
| 549 | 553 |
| 550 void AudioInputController::DoLogAudioLevel(float level_dbfs) { | 554 void AudioInputController::DoLogAudioLevels(float level_dbfs, |
| 555 int microphone_volume_percent) { | |
| 551 #if defined(AUDIO_POWER_MONITORING) | 556 #if defined(AUDIO_POWER_MONITORING) |
| 552 DCHECK(task_runner_->BelongsToCurrentThread()); | 557 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 553 if (!handler_) | 558 if (!handler_) |
| 554 return; | 559 return; |
| 555 | 560 |
| 556 std::string log_string = base::StringPrintf( | 561 std::string log_string = base::StringPrintf( |
| 557 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); | 562 "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); |
| 558 static const float kSilenceThresholdDBFS = -72.24719896f; | 563 static const float kSilenceThresholdDBFS = -72.24719896f; |
| 559 if (level_dbfs < kSilenceThresholdDBFS) | 564 if (level_dbfs < kSilenceThresholdDBFS) |
| 560 log_string += " <=> no audio input!"; | 565 log_string += " <=> no audio input!"; |
| 561 handler_->OnLog(this, log_string); | 566 handler_->OnLog(this, log_string); |
| 562 | 567 |
| 563 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); | 568 UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS); |
| 569 | |
| 570 UMA_HISTOGRAM_PERCENTAGE("Media.MicrophoneVolume", microphone_volume_percent); | |
| 571 log_string = base::StringPrintf( | |
| 572 "AIC::OnData: microphone volume=%d percent", microphone_volume_percent); | |
| 573 handler_->OnLog(this, log_string); | |
| 564 #endif | 574 #endif |
| 565 } | 575 } |
| 566 | 576 |
| 567 void AudioInputController::OnError(AudioInputStream* stream) { | 577 void AudioInputController::OnError(AudioInputStream* stream) { |
| 568 // Handle error on the audio-manager thread. | 578 // Handle error on the audio-manager thread. |
| 569 task_runner_->PostTask(FROM_HERE, base::Bind( | 579 task_runner_->PostTask(FROM_HERE, base::Bind( |
| 570 &AudioInputController::DoReportError, this)); | 580 &AudioInputController::DoReportError, this)); |
| 571 } | 581 } |
| 572 | 582 |
| 573 void AudioInputController::DoStopCloseAndClearStream() { | 583 void AudioInputController::DoStopCloseAndClearStream() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 } | 626 } |
| 617 | 627 |
| 618 void AudioInputController::LogSilenceState(SilenceState value) { | 628 void AudioInputController::LogSilenceState(SilenceState value) { |
| 619 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", | 629 UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
| 620 value, | 630 value, |
| 621 SILENCE_STATE_MAX + 1); | 631 SILENCE_STATE_MAX + 1); |
| 622 } | 632 } |
| 623 #endif | 633 #endif |
| 624 | 634 |
| 625 } // namespace media | 635 } // namespace media |
| OLD | NEW |