Chromium Code Reviews| Index: media/audio/audio_input_controller.cc |
| diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc |
| index 490c62b3c16df6794d1ff6d17d18147f9c759a2c..fd9a2b6bda296f032d1837fd42dbc0e2b9babbd9 100644 |
| --- a/media/audio/audio_input_controller.cc |
| +++ b/media/audio/audio_input_controller.cc |
| @@ -63,6 +63,9 @@ AudioInputController::AudioInputController(EventHandler* handler, |
| sync_writer_(sync_writer), |
| max_volume_(0.0), |
| user_input_monitor_(user_input_monitor), |
| +#if defined(AUDIO_POWER_MONITORING) |
| + silence_state_(SILENCE_STATE_NO_MEASUREMENT), |
| +#endif |
| prev_key_down_count_(0) { |
| DCHECK(creator_task_runner_.get()); |
| } |
| @@ -203,6 +206,7 @@ void AudioInputController::DoCreate(AudioManager* audio_manager, |
| params.sample_rate(), |
| TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMilliseconds))); |
| audio_params_ = params; |
| + silence_state_ = SILENCE_STATE_NO_MEASUREMENT; |
| #endif |
| // TODO(miu): See TODO at top of file. Until that's resolved, assume all |
| @@ -307,6 +311,13 @@ void AudioInputController::DoClose() { |
| if (user_input_monitor_) |
| user_input_monitor_->DisableKeyPressMonitoring(); |
| +#if defined(AUDIO_POWER_MONITORING) |
| + // Send UMA stats if we have enabled power monitoring. |
| + if (audio_level_) { |
| + LogSilenceState(silence_state_); |
| + } |
| +#endif |
| + |
| state_ = CLOSED; |
| } |
| @@ -474,8 +485,18 @@ void AudioInputController::DoLogAudioLevel(float level_dbfs) { |
| std::string log_string = base::StringPrintf( |
| "AIC::OnData: average audio level=%.2f dBFS", level_dbfs); |
| static const float kSilenceThresholdDBFS = -72.24719896f; |
| - if (level_dbfs < kSilenceThresholdDBFS) |
| + if (level_dbfs < kSilenceThresholdDBFS) { |
| log_string += " <=> no audio input!"; |
| + if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT) |
| + silence_state_ = SILENCE_STATE_ONLY_SILENCE; |
| + else if (silence_state_ == SILENCE_STATE_NO_SILENCE) |
|
tommi (sloooow) - chröme
2014/08/13 18:28:04
nit: I find "NO_SILENCE" to be a bit confusing whe
Henrik Grunell
2014/08/14 11:21:45
I changed it to ONLY_AUDIO. And the PARTIAL_SILENC
|
| + silence_state_ = SILENCE_STATE_PARTIAL_SILENCE; |
|
tommi (sloooow) - chröme
2014/08/13 18:28:04
nit:
else
DCHECK_EQ(silence_state_, SILENCE_STAT
Henrik Grunell
2014/08/14 11:21:45
Well it can be that or ONLY_SILENCE. Done.
|
| + } else { |
| + if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT) |
| + silence_state_ = SILENCE_STATE_NO_SILENCE; |
| + else if (silence_state_ == SILENCE_STATE_ONLY_SILENCE) |
| + silence_state_ = SILENCE_STATE_PARTIAL_SILENCE; |
|
tommi (sloooow) - chröme
2014/08/13 18:28:04
nit: same else case here. good for sanity checkin
Henrik Grunell
2014/08/14 11:21:45
Done.
|
| + } |
| handler_->OnLog(this, log_string); |
| #endif |
| @@ -509,4 +530,12 @@ bool AudioInputController::GetDataIsActive() { |
| return (base::subtle::Acquire_Load(&data_is_active_) != false); |
| } |
| +#if defined(AUDIO_POWER_MONITORING) |
| +void AudioInputController::LogSilenceState(SilenceState value) { |
| + UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport", |
| + value, |
| + SILENCE_STATE_MAX + 1); |
| +} |
| +#endif |
| + |
| } // namespace media |