Commit 59898b22 authored by grunell@chromium.org's avatar grunell@chromium.org

Only log audio input silence state UMA stats for low latency mode and if not fake device.

The stats is intended for the low latency case, hence removing other cases.

NOTRY=true

Review URL: https://codereview.chromium.org/486633003

Cr-Commit-Position: refs/heads/master@{#291402}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291402 0039d316-1c4b-4281-b951-d872f2087c98
parent 64ffaba7
......@@ -8,6 +8,7 @@
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "media/audio/audio_parameters.h"
#include "media/base/limits.h"
#include "media/base/scoped_histogram_timer.h"
#include "media/base/user_input_monitor.h"
......@@ -85,6 +86,7 @@ AudioInputController::AudioInputController(EventHandler* handler,
max_volume_(0.0),
user_input_monitor_(user_input_monitor),
#if defined(AUDIO_POWER_MONITORING)
log_silence_state_(false),
silence_state_(SILENCE_STATE_NO_MEASUREMENT),
#endif
prev_key_down_count_(0) {
......@@ -150,7 +152,7 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency(
// Create and open a new audio input stream from the existing
// audio-device thread. Use the provided audio-input device.
if (!controller->task_runner_->PostTask(FROM_HERE,
base::Bind(&AudioInputController::DoCreate, controller,
base::Bind(&AudioInputController::DoCreateForLowLatency, controller,
base::Unretained(audio_manager), params, device_id))) {
controller = NULL;
}
......@@ -238,6 +240,21 @@ void AudioInputController::DoCreate(AudioManager* audio_manager,
DoCreateForStream(audio_manager->MakeAudioInputStream(params, device_id));
}
void AudioInputController::DoCreateForLowLatency(AudioManager* audio_manager,
const AudioParameters& params,
const std::string& device_id) {
DCHECK(task_runner_->BelongsToCurrentThread());
#if defined(AUDIO_POWER_MONITORING)
// We only log silence state UMA stats for low latency mode and if we use a
// real device.
if (params.format() != AudioParameters::AUDIO_FAKE)
log_silence_state_ = true;
#endif
DoCreate(audio_manager, params, device_id);
}
void AudioInputController::DoCreateForStream(
AudioInputStream* stream_to_control) {
DCHECK(task_runner_->BelongsToCurrentThread());
......@@ -329,10 +346,10 @@ void AudioInputController::DoClose() {
user_input_monitor_->DisableKeyPressMonitoring();
#if defined(AUDIO_POWER_MONITORING)
// Send UMA stats if we have enabled power monitoring.
if (audio_level_) {
// Send UMA stats if enabled.
if (log_silence_state_)
LogSilenceState(silence_state_);
}
log_silence_state_ = false;
#endif
state_ = CLOSED;
......@@ -503,26 +520,11 @@ 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_ONLY_AUDIO)
silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
else
DCHECK(silence_state_ == SILENCE_STATE_ONLY_SILENCE ||
silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
} else {
if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT)
silence_state_ = SILENCE_STATE_ONLY_AUDIO;
else if (silence_state_ == SILENCE_STATE_ONLY_SILENCE)
silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
else
DCHECK(silence_state_ == SILENCE_STATE_ONLY_AUDIO ||
silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
}
handler_->OnLog(this, log_string);
UpdateSilenceState(level_dbfs < kSilenceThresholdDBFS);
#endif
}
......@@ -555,6 +557,28 @@ bool AudioInputController::GetDataIsActive() {
}
#if defined(AUDIO_POWER_MONITORING)
void AudioInputController::UpdateSilenceState(bool silence) {
if (silence) {
if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT) {
silence_state_ = SILENCE_STATE_ONLY_SILENCE;
} else if (silence_state_ == SILENCE_STATE_ONLY_AUDIO) {
silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
} else {
DCHECK(silence_state_ == SILENCE_STATE_ONLY_SILENCE ||
silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
}
} else {
if (silence_state_ == SILENCE_STATE_NO_MEASUREMENT) {
silence_state_ = SILENCE_STATE_ONLY_AUDIO;
} else if (silence_state_ == SILENCE_STATE_ONLY_SILENCE) {
silence_state_ = SILENCE_STATE_AUDIO_AND_SILENCE;
} else {
DCHECK(silence_state_ == SILENCE_STATE_ONLY_AUDIO ||
silence_state_ == SILENCE_STATE_AUDIO_AND_SILENCE);
}
}
}
void AudioInputController::LogSilenceState(SilenceState value) {
UMA_HISTOGRAM_ENUMERATION("Media.AudioInputControllerSessionSilenceReport",
value,
......
......@@ -191,11 +191,11 @@ class MEDIA_EXPORT AudioInputController
SyncWriter* sync_writer,
UserInputMonitor* user_input_monitor);
// Factory method for creating an AudioInputController for low-latency mode,
// taking ownership of |stream|. The stream will be opened on the audio
// thread, and when that is done, the event handler will receive an
// OnCreated() call from that same thread. |user_input_monitor| is used for
// typing detection and can be NULL.
// Factory method for creating an AudioInputController with an existing
// |stream| for low-latency mode, taking ownership of |stream|. The stream
// will be opened on the audio thread, and when that is done, the event
// handler will receive an OnCreated() call from that same thread.
// |user_input_monitor| is used for typing detection and can be NULL.
static scoped_refptr<AudioInputController> CreateForStream(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
EventHandler* event_handler,
......@@ -251,6 +251,12 @@ class MEDIA_EXPORT AudioInputController
// Elements in this enum should not be deleted or rearranged; the only
// permitted operation is to add new elements before SILENCE_STATE_MAX and
// update SILENCE_STATE_MAX.
// Possible silence state transitions:
// SILENCE_STATE_AUDIO_AND_SILENCE
// ^ ^
// SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE
// ^ ^
// SILENCE_STATE_NO_MEASUREMENT
enum SilenceState {
SILENCE_STATE_NO_MEASUREMENT = 0,
SILENCE_STATE_ONLY_AUDIO = 1,
......@@ -268,6 +274,9 @@ class MEDIA_EXPORT AudioInputController
// Methods called on the audio thread (owned by the AudioManager).
void DoCreate(AudioManager* audio_manager, const AudioParameters& params,
const std::string& device_id);
void DoCreateForLowLatency(AudioManager* audio_manager,
const AudioParameters& params,
const std::string& device_id);
void DoCreateForStream(AudioInputStream* stream_to_control);
void DoRecord();
void DoClose();
......@@ -292,6 +301,11 @@ class MEDIA_EXPORT AudioInputController
bool GetDataIsActive();
#if defined(AUDIO_POWER_MONITORING)
// Updates the silence state, see enum SilenceState above for state
// transitions.
void UpdateSilenceState(bool silence);
// Logs the silence state as UMA stat.
void LogSilenceState(SilenceState value);
#endif
......@@ -345,6 +359,9 @@ class MEDIA_EXPORT AudioInputController
media::AudioParameters audio_params_;
base::TimeTicks last_audio_level_log_time_;
// Whether the silence state should sent as UMA stat.
bool log_silence_state_;
// The silence report sent as UMA stat at the end of a session.
SilenceState silence_state_;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment